user3312792 user3312792 - 1 month ago 8
Apache Configuration Question

prepend directory to all urls mod rewrite

I am using htaccess on localhost, my htaccess is:

RewriteEngine On
RewriteBase /website/files/

RewriteRule ^home/?$ home.php [NC]
RewriteRule ^page/?$ page.php [NC]


This url works:

http://localhost/website/files/home


But when hovering over links on the page they are displayed as:

http://localhost/page


Instead of:

http://localhost/website/files/page


All links in the page are set as:

<a href="/page">page</a>


How can I prepend the directory to all urls in htaccess?

Answer

Create this .htaccess in the site root .htaccess:

RewriteEngine On

RewriteRule .* website/files/$0 [L]

Keep your website/files/.htaccess as you've shown in question.

Comments