Stichy Stichy - 1 year ago 130
PHP Question

mod-rewrite 2 parameters and include paths

I have 2 parameters cat and page_id

Today my URL:s are like:

Can this be translated to ?

I have tried this in .htaccess:

RewriteEngine on
RewriteRule ^([\S-]+)/([\S-]+)/?$ ?cat=$1&page=$2 [L]

When I surf in to my CSS-link (css/style.css) counts as category and page_id and will therefor not load.

Any ideas?

Answer Source

You have to add exceptions like file or directory with this code before RewriteRule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

This will exclude all the situations when existing files or directories are requested.

So your final .htaccess file should look like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\S-]+)/([\S-]+)/?$   ?cat=$1&page=$2 [L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download