Forum Moderators: phranque
RewriteRule (.*)-(.*)\.htm$ /proddetail.php?prod=$1&cat=$2
Now my question is, how do I re-direct the currently indexed urls to their new static versions?
For example:
somedomain.com/proddetail.php?prod=7&cat=4
==> Need to redirect to: somedomain.com/7-4.htm
Ideas?
RewriteRule ^proddetail\.php\?prod\=([0-9]+)\&cat\=([0-9]+)$ $1-$2.htm [R=301,L] RewriteCond %{QUERY_STRING} ^prod\=([^&]+)\&cat\=([^&]+)$
RewriteRule ^$ %1-%2.htm [R=301,L] Again, I'm trying to get the dynamic URLs:
/proddetail.php?prod=1&cat=2
To redirect to their static versions:
/1-2.htm
# Rewrite static URLs to dynamic
RewriteRule ([^-]+)-([^.]+)\.htm$ /proddetail.php?prod=$1&cat=$2 [L]
#
# Redirect only client-requested dynamic URLs to static
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /proddetail\.php\?prod=([^&]+)&cat=([^&]+)
RewriteRule ^proddetail\.php$ http://www.example.com/%1-%2.htm [R=301,L]
# Rewrite static URLs to dynamic
RewriteRule ([^-]+)-([^.]+)\.htm$ /proddetail.php?prod=$1&cat=$2 [L]
#
# Redirect only client-requested dynamic URLs to static
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /proddetail\.php\?prod=([^&]+)&cat=([^&]+)
RewriteRule ^proddetail\.php$ http://www.domain.com/%1-%2.htm [R=301,L]
Which lets the static urls render properly, but the dynamic urls now coming up with an error. This time the error comes out in the url
(which goes to a 404 page):
domain.com/27-12%20HTTP/1.1.htm?prod=27&cat=12
It's picking up the "space and HTTP/1.1" tail of THE_REQUEST.
Change the rewritecond to:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /proddetail\.php\?prod=([^&]+)&cat=([^&\ ]+)
GET /proddetail.php?prod=7&cat=4 HTTP/1.1
Since I forgot to stop the pattern-match on the space, it just kept going, since it didn't find an ampersand and another variable after cat=4.
JIm
For some reason the url still contains the dynamic variable at the end, example:
proddetail.php?prod=7&cat=13
now redirects to:
/7-13.htm?prod=7&cat=13
using this code:
# Rewrite static URLs to dynamic
RewriteRule ([^-]+)-([^.]+)\.htm$ /proddetail.php?prod=$1&cat=$2 [L]
#
# Redirect only client-requested dynamic URLs to static
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /proddetail\.php\?prod=([^&]+)&cat=([^&\ ]+)
RewriteRule ^proddetail\.php$ http://www.domain.com/%1-%2\.htm [R=301,L] Should redirect to just: /7-13.htm (without the? mark and query string)
Thanks for all the help!