Welcome to WebmasterWorld Guest from 54.227.72.69

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

.htacess Question - Newbie Stuck - Please Help

I am trying to redirect links..please advice

     
9:53 am on Jan 6, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 28, 2003
posts: 43
votes: 0


I am trying to redirect hundreds of pages on our site that have this structure
http://www.example.com/folder/page.php?id=1 (where id value changes)
to new links of this structure
http://www.example.com/folder/newlandingpage.php?id=1 (where id value changes)

Will these instructions work or what is the correct way of doing this...

RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^/folder/folder.php?id=(.*)$ /folder/newlandingpage.php?id=$2

[edited by: encyclo at 11:11 am (utc) on Jan. 6, 2009]
[edit reason] switched to example.com [/edit]

10:56 am on Jan 6, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10563
votes: 15


it depends on exactly what you are trying to do and what results you got from which request.
if this is in .htaccess context, then you are using the local url-path, so the leading (directory) slash is stripped.
also, if you are redirecting you should specify a fully qualified url and/or add an [R] flag.

this might work:
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^folder/page.php?id=(.*)$ http://www.example.com/folder/newlandingpage.php?id=$1 [R=301,L]

12:28 pm on Jan 6, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 28, 2003
posts: 43
votes: 0


Thanks for the reply...i am also trying to achieve a 301 redirect in the process for the search engine does [R=301,L] cover this?
1:14 pm on Jan 6, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10563
votes: 15


yes, but you should be curious enough to read the relevant parts of this document very carefully so you understand exactly what you are getting with that code:
mod_rewrite - Apache HTTP Server [httpd.apache.org]
1:26 pm on Jan 6, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 7, 2004
posts:929
votes: 0


Hi 3Mice,

If not sure, just do a test locally. Then, once it is OK locally, just upload your .htaccess online.

Also, do not forget to update your XML sitemap as well as playing with the URL removal request and doing other stuff on the Google Webmaster Tools.

Personnal note: bas, imetosha :)

2:12 pm on Jan 6, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 28, 2003
posts:43
votes: 0


This one has worked

RewriteCond %{QUERY_STRING} ^id=(.+)
RewriteRule ^folder/page.php$ [mysite.com...] [QSA,L,R=301]

3:40 am on Jan 7, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10563
votes: 15


RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^folder/page.php?id=(.*)$ http://www.example.com/folder/newlandingpage.php?id=$1 [R=301,L]

sorry - i forgot when i wrote the above rule that the pattern doesn't match the query string in the RewriteRule.
as you noticed you can use the QSA flag to reuse the old query string.
if you had needed to use part of the old query string you could have done it thusly:
RewriteCond %{QUERY_STRING} ^id=(.+)$
RewriteRule ^folder/page.php$ http://www.example.com/folder/newlandingpage.php?newidparam=%1 [R=301,L]