Manny Manny - 3 months ago 7
Apache Configuration Question

How to create rewrite rule that allows to rewrite something right after slash with exceptions

i want to create these rewrite rules:

From:

www.something.com/name-of-some-product


To:

www.something.com/index.php?site=name-of-some-product


But I also need to use images and some other files and also other PHP files.

The .htaccess i have:

RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.css)$
RewriteRule ^(.*)$ index.php?site=$1 [QSA]


The problem is when i try to load file like this:

www.something.com/another_php_file.php?parameter=value


It doesn't work, because i don't know how to avoid rewriting PHP files.

Answer

Try this Rule,

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?site=$1 [QSA]