Hi
I have in my .htaccess the following:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite/index.php?q=$1 [L,QSA]
This RewriteRule works fine for ’mysite’ on my localhost development machine. Standard modX .htaccess.
Now, I have hundreds of products in a database, and would like to serve any one of them up from the one page mysite/product (resource with alias "product") but with unique urls for SEO (ie. not mysite/product?pid=77. So when a user enters mysite/productId/77 (which is a non-existent page) they would be redirected to mysite/product with a GET var of pid=77. ie. Google would see this as mysite/productId/77. I would then use a snippet to retrieve the info relating to product 77 from the database and display it on the page.
So I added a new rule to the .htaccess which now reads:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Additional rewrite to handle listings redirect
RewriteRule ^(.*)/productId/([0-9]+)$ /mysite/index.php?q=product&pid=$2 [L,QSA]
# Original modx rewrite rule
RewriteRule ^(.*)$ /mysite/index.php?q=$1 [L,QSA]
Argh!, it breaks!
There must be a conflict or something here - Both rules work fine, but ONLY if one is commented out, ie, the first rewrite rule works fine and redirects mysite/productId/77 to mysite/product (with a GET var of pid=77) if the second rule is commented out. If I don’t comment the second rule out I get a Internal Server Error 500.
The same applies for the url mysite/contactUs, it’s fine ONLY IF I comment out the first rule. This is driving me nuts!
I need both rules! Can any of you mod_rewrite gurus see what I’m doing wrong here?
Thanks