Forum Moderators: phranque
I have three different url patterns
index.php?cat=11
index.php?subcat=18
index.php?cat=46&product=testing
I have the bellow in my htaccess
#redirect cat
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /testdir/index\.php\?cat=([a-z]+) [NC]
RewriteRule ^index\.php$ [domain.co.uk...] [R=301]
RewriteRule ^([a-z-]+)/?$ index.php?cat=$1 [NC]
# Redirect for cat and product
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /spw/home2garden/index\.php\?cat=([a-z]+)\&product=([a-z-]+)
RewriteRule ^index\.php$ [domain.co.uk...] [R=301]
RewriteRule ^cat/([a-z-]+)/([a-z-]+).html?$ index.php?cat=$1&product=$2 [NC]
They work perfectly if only one of the above is present, either cat or product and cat. When I run the two param query string the result is a re-written and redirect url with only the first query string param.
I feel one is over writing the other. I thought the purpose of the rewritecond is so the rewrite work on a certain condition.
my rewrites work well but I just need to re-direct all instances of the query string regardless of how many are within the url.
if anyone can give me any guidance it would be greatly appreciated.
I'm nearly there!
now when both are enabled no # the second querystring cat/productname would give the same output as the first!
I just thought I would make this slightly clearer
they both work, just not together!
# Redirect direct client requests for cat and product dynamic URL back to static URL
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /testdir/index\.php\?cat=([a-z\-]+)&product=([a-z\-]+)\ HTTP/ [NC]
RewriteRule ^index\.php$ http://example.co.uk/testdir/cat/%1/%2.html? [R=301,L]
#
# Redirect direct client requests for cat dynamic URL back to static URL
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /testdir/index\.php\?cat=([a-z\-]+)\ HTTP/ [NC]
RewriteRule ^index\.php$ http://example.co.uk/testdir/%1/? [R=301,L]
#
# Internally rewrite static cat and product URLs to dynamic filepaths
RewriteRule ^cat/([a-z\-]+)/([a-z\-]+)\.html?$ index.php?cat=$1&product=$2 [NC,L]
RewriteRule ^([a-z\-]+)/?$ index.php?cat=$1 [NC,L]
You should also pick one or the other of URLs ending with a trailing slash versus not ending with a trailing slash, and URLs ending with ".html" versus those ending with ".htm". Redirect the non-preferred URLs to the preferred ones, and then remove the "permissiveness" from the rules above. Allowing two different URLs to access the same content creates a duplicate-content issue -- one you can read about in many threads here.
Jim
To answer your question to why the cat has a trailing forward slash is on the basis of the cat is a directory in my opinion and the product is a inner page so I wanted a file extension added to this.
The rewrite was intended to create categories as directory’s and products as html files. (I appreciate you not changing the pattern)!
Thanks again.