Hi, I'm having a problem with what seems to be conflicting URL rewrite rules. Basically the first and second rule work individually but when i add both together the second rewrite rule no longer works.

RewriteEngine On 
RewriteBase /
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 


RewriteRule ^(.*)$ site/index.php?content=$1 [L] [NC]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/$ /site/index.php?content=$1&pageNum_gproducts=$2&totalRows_gproducts=$3 [L]

I am not great with mod rewrite so any help is much appreciated

The first one rewrites all URLs, so the second never gets executed. Reverse their order.

Thanks for the quick reply, i did try that but for some reason it seems to break the link to the css page. I use root relative links but even if i use the full url it does not seem to load.

However, if i take the second rule out so its like this they load no problem. Any ideas?

RewriteEngine On
    RewriteBase /
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/$ /site/index.php?content=$1&pageNum_gproducts=$2&totalRows_gproducts=$3 [L]

I have also just checked the admin system and it also seems to be getting redirected now. If i go to /admin/login.php the index page is loaded without any css.

So, it seems like the rule is being matched while disregarding that this is an actual file.

Am not entirely sure whether the rewritecond acts like an 'or', ignoring the second and third if the first evaluates to true.

The second and third variable will always be a number for purposes of the rule so I thought something like this would work but it does not. I'm not sure if the rule is correct but i was hoping that this would cause the rule to fail if it was a directory/file as they would never be only a number.

RewriteRule ^([^/]*)/([0-9]+)/([0-9]+)$ /site/index.php?content=$1&pageNum_gproducts=$2&totalRows_gproducts=$3 [L]

I was talking about the RewriteCond's, not the RewriteRule.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.