Forum Moderators: phranque

Message Too Old, No Replies

301 redirect for dynamic pages

         

fakestar

6:26 am on Jun 12, 2007 (gmt 0)

10+ Year Member



Hi,

I need help to permanent redirect some dynamic URL's to static html.

Example:

http://www.example.com/pages/index.php?page=name-of-article

to

http://www.example.com/pages/name-of-article.html

I tried this:

RewriteRule ^pages/index.php?page=name-of-article$ http://www.example.com/pages/name-of-article.html? [R=301,L]

but it didn't work. What am i doing wrong?

Can anyone help me? Thanks in advance.

jdMorgan

2:47 pm on Jun 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a description of the whole friendly-URL rewrite and redirect process: Changing dynamic to static urls -- Search engine-friendly links with mod_rewrite [webmasterworld.com]

Jim

fakestar

4:44 pm on Jun 12, 2007 (gmt 0)

10+ Year Member



Thanks, i read the article, but it didn't work for me.

I tried to put \:

RewriteRule ^pages/index\.php?page=name-of-article$ http://www.example.com/pages/name-of-article.html? [R=301,L]

i need to redirect specific pages only, i think that example is if i want redirect all dynamic URLs to friendly ones, right?

i mean, i need to redirect 301 http://example.com/pages/index.php?page=name-of-article to http://example.com/2.html for example, i don't need friendly URL

jdMorgan

9:03 pm on Jun 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't try to "recognize" query strings using RewriteRule -- You must use a RewriteCond to examine the %{QUERY_STRING} variable, in addition examining the URL-path with RewriteRule.

RewriteCond %{QUERY_STRING} [&]?page=name-of-article[&]?
RewriteRule ^pages/index\.php$ http://www.example.com/pages/name-of-article.html? [R=301,L]

The [&]? subpatterns are "guards" around the un-anchored name/value-pair pattern. This is to prevent, for example, query strings such as
new-page=name-of-article
or
page=name-of-article-updated
from ever matching.

In other words, if any character precedes or follows the name/value string you're matching, it must be an ampersand.

If you only ever have that one name/value pair, this won't be needed and you can simply start- and end-anchor the pattern as usual with "^" and "$"

Jim

fakestar

12:23 am on Jun 23, 2007 (gmt 0)

10+ Year Member



works perfect.
Thank you very much! :)