homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

how to get rid of the query string appended in the rewritten rule.

 7:02 pm on Feb 27, 2006 (gmt 0)

I am trying to redirect the following URL:

old URL: /resources/abc.php?x=a1234
new URL: /r-abc-x-a1234

I need to do this to redirect old bookmarked URLs to the new SEO friendly ones.

This is the rule I am using:

RewriteCond %{QUERY_STRING} ^([a-z]+)=([a-z_0-9]+)$
RewriteRule ^/resources/(.*).php$ /r-$1-%1-%2 [R=301,L]

I am getting this result-

As you can see, I am getting close to the final result however getting that query string appended to the redirected URL.

How can I avoid that? I am new to mod_rewrite and learning a lot through your excellent web site. However, not able to crack this issue.

Any help would be much appreciated.

Thanks a bunch.



 7:10 pm on Feb 27, 2006 (gmt 0)


Welcome to WebmasterWorld!

Just add a question mark to the substitution URL to clear the query string:

RewriteRule ^/resources/(.*).php$ http://www.example.com/r-$1-%1-[b]%2?[/b] [R=301,L]

This question mark will not "show" in the redirected URL. I also suggest you use canonical URLs with redirects as shown, to prevent problems if the server's UseCanonicalName setting is enabled in the future.



 8:55 pm on Feb 27, 2006 (gmt 0)

Hi Jim,

Thanks a lot for the very quick reply. It works fine after appending the?.

I am not sure I understand what you mean by Canonical urls. I'll try searching the site on this.

Thanks again and keep up the good work...



 9:04 pm on Feb 27, 2006 (gmt 0)

As used here, the canonical URL is the result of the http://www.example.com part I added to the substitution URL.


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