Reputation: 19778
I have the following files on my server root:
/index.php
/css/file.css
/js/file.js
I would like to redirect :
http://host/entry/1
to http://host/index.php?entry=1
I have the following .htaccess
so far:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /entry/ [NC]
RewriteRule ^entry/(.*)$ index.php?entry=$1 [QSA,NC,L]
</IfModule>
The problem is that the css
and js
files are not served correctly.
And that is because the browser asks for the files:
http://host/entry/css/file.css
instead of http://host/css/file.css
http://host/entry/js/file.js
instead of http://host/js/file.js
How can I fix that?
Thanks
Upvotes: 0
Views: 27
Reputation: 18671
Use that:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^ - [L]
RewriteRule ^entry/(.+\.(?:js|css))$ $1 [NC,L]
RewriteRule ^/content/ag(.*)$ index.php?entry=$1 [QSA,NC,L]
RewriteRule ^entry/(.*)$ index.php?entry=$1 [QSA,NC,L]
</IfModule>
And add in your html header:
<base href="/">
I add rewrite for .js and .css
But you can add others, like .gif or .png...
Upvotes: 1