homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

.htacess Question - Newbie Stuck - Please Help
I am trying to redirect links..please advice

 9:53 am on Jan 6, 2009 (gmt 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)

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)

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)

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)

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)

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)

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]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved