How to create url’s friendly with . htaccess pointing to a different path from where the referenced file is?

Asked

Viewed 49 times

1

I have a question regarding making the URL friendly for a site, I believe the title is not very clear, but would be the following:

I am doing a maintenance on an old site in PHP, it was written so that the page structures (header, side menu, content and footer) were divided into separate files. Then all pages have a link to the other structure files using the include of PHP.

It turns out that all the pages were created at the root of the site, IE, are over 100 pages that are "played" and I would like to organize them better creating categories, in the case of products. The problem is that I wanted to do this just by rewriting the URL by htaccess, yet still keeping the pages at the root because that way all the files and external links are already referenced, ie, if I create subfolders I would lose for example the references of scripts and external styles.


TL;DR

I would like to do something like "category/product/by-product" by changing only the URL, without necessarily creating subfolders for it. Otherwise I lose the references of external files (because it does not compensate for me to change one by one because there are many!)

Would have some solution to get around this problem?

Thank you!

  • Leandro, achilo I understood and edited the title, if you think it’s not good you can reverse the edition.

  • Maybe this question will help. https://answall.com/questions/53973/url-amig%C3%A1vel-como-fazer-funcionar-com-htaccess

  • Thanks guys! Problem solved

  • Leandro, if you want you can leave an answer with the solution found, to serve as reference to other people who arrive at this page.

  • Okay @gustavox, thanks for the tips

1 answer

-2


The problem was solved using the following tag in my page header:

<base href="/">

Thus, as all links to external files were from the index, now is added a "/" which now means that the links are relative to root (independent of subdirectories).

Note: There is another alternative which is the command RewriteBase of the . htaccess file, but for some reason I could not, only with the tag <base> even.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.