ยป Smart Phones, Web Design, Google or whatever
Redirecting Dynamic URL to Static using .htaccess
I (finally) found some documentation today on how to redirect a dynamic URL to a static URL. For example changing www.example.com/page.php?article=22 to www.example.com/apples-and-oranges.php
This is your .htaccess file entry to do the above redirection, of course the RewriteEngine on command is only needed once before the first redirect… This will work for ONE variable pair
RewriteEngine on
RewriteCond %{QUERY_STRING} ^article=22$
RewriteRule ^page\.php$ http://www.example.com/apples-and-oranges.php? [R=301,L]
Now if you need to redirect a dynamic URL with more than one name/value pair like this:
www.example.com/page.php?widget=cellphone22&color=red
You will need to use the following code:
RewriteEngine on
RewriteCond %{QUERY_STRING} [&]?widget=cellphone22[&]?
RewriteRule ^page\.php$ www.example.com/cellphone22.php? [R=301,L]
In this last example, &color=22 is ignored.
Resources for this post:
http://www.webmasterworld.com/apache/3365089.htm
http://www.seoverflow.com/blog/seo/setting-up-301-redirects-for-dynamic-urls/
| Print article | This entry was posted by George on March 11, 2010 at 11:53 am, and is filed under Web Design. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
ABOUT COMMENTING ON THIS BLOG
Comments are moderated by a human and will be approved if they bring value to the discussion. This means comments are on topic, relevant and useful. Here are some ways to insure your comment is rejected, marked as spam or will be edited (at my discretion):
- Using keywords, business names or website names in the Name field
- Putting a spammy site/page in the Website field
- Foul, abusive or discriminatory language
- Comments for SEO only purposes