homepage Welcome to WebmasterWorld Guest from 54.166.8.138
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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.
newlearner2006




msg:1505438
 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-
http://example.com/r-abc-x-a1234?x=a1234

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.

 

jdMorgan




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

newlearner2006,

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.

Jim

newlearner2006




msg:1505440
 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...

newlearner2006

jdMorgan




msg:1505441
 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.

Jim

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