Forum Moderators: phranque
RedirectMatch 301 ^/items/(hat¦shirt¦pants)\.php?id=(.+)$ [mysite.com...]
RewriteEngine on
RewriteRule ^(hat¦shirt¦pants)/(hat¦shirt¦pants)_prices/(.+).html$ /items/$1.php?id=$3
Welcome to WebmasterWorld.
You will need to use mod_rewrite for both or you will create an infinite loop. Currently, your redirect sends uses to the static location, then your rewrite forces Apache to open the .php location, but Apache is redirected to the new location by the redirect, where it tries to open the .php location, but is then reidrected...
The only way to break the loop is using %{THE_REQUEST} from mod_rewrite:
RewriteEngine on
RewriteCond %{THE_REQUEST} \?id=(.+)
RewriteRule ^items/(hat¦shirt¦pants)\.php$ http://www.mysite.com/$1/$1_prices/%1.html [R=301,L]
RewriteRule ^(hat¦shirt¦pants)/(hat¦shirt¦pants)_prices/(.+).html$ /items/$1.php?id=$3 [L]
%{THE_REQUEST} will only redirect original requests, so you will be able to redirect when a URL is clicked on, typed into a browser, or spidered, but will not redirect if the request is from a rewrite.
Hope this helps.
Justin
Still a little tired, so you might find some efficiency somewhere, but this is the general idea.
RewriteCond %{THE_REQUEST} \?id=(.+)$
the page is redirected, but it appears as:
[mysite.com...]
how do I get rid of the?id=(.+)?
RewriteCond %{THE_REQUEST} \?id=(.+)
RewriteRule ^items/(hat¦shirt¦pants)\.php$ http://www.mysite.com/$1/$1_prices/%1.html? [R=301,L]
Should be better -- Make sure you empty your cache.
Justin
Added: The $ is not at the end of the line...
RewriteCond %{THE_REQUEST} \?id=(.+)\ /HTTP1\.(0¦1)$
Would be the full line ending (or close to it) better to use the implicit 'and everything else' by leaving the anchor off.