Forum Moderators: phranque
Let me give the quick rundown. I have a .htaccess file to rewrite my long URL's to 'static' URL's. These were working fine until I added a line to redirect my sub-domains to a new folder structure.
So Here's what I need to accomplish:
http://widgets.example.com/show.php?widget=123 -> http://example.com/widgets/showwidget123.htm
But instead it's doing this:
http://example.com/widgets/show.php?widget=123
Here's my .htaccess file:
RewriteEngine On
RewriteRule showwidget(.*)\.htm$ /show.php?widget=$1
RewriteCond %{HTTP_HOST} ^widgets.example.com
RewriteRule (.*) http://www.example.com/widgets/$1 [R=301,L]
[edited by: jdMorgan at 11:27 pm (utc) on Nov. 17, 2005]
[edit reason] Example.com [/edit]
The usual technique used is to:
This last step speeds up the elimination of your dynamic URLs from the SERPs, and reduces the chance that someone will link to the dynamic page.
My best guess at what this would look like on your site is:
RewriteEngine on
#
# Externally redirect direct client requests for dynamic URLs to static URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /show\.php\?widget=([^&\ ]+)\ HTTP/
RewriteRule ^show\.php$ http://widgets.example.com/showwidget%1.htm [R=301,L]
#
# Internally rewrite subdomain to separate subdirectory, while preventing 'infinite' loop
RewriteCond $1!^widgets/
RewriteCond %{HTTP_HOST} ^widgets\.example\.com
RewriteRule (.*) /widgets/$1
#
# Internally rewrite static showwidgetNN.htm URL requests to show.php script
RewriteRule ^widgets/showwidget([^.]+)\.htm$ /widgets/show.php?widget=$1 [L]