Majid Laissi
Majid Laissi

Reputation: 19778

htaccess Rewrite rules with parameters

I have the following files on my server root:

/index.php
/css/file.css
/js/file.js

I would like to redirect :

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:

How can I fix that?

Thanks

Upvotes: 0

Views: 27

Answers (1)

Croises
Croises

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

Related Questions