Welcome to WebmasterWorld Guest from 34.229.194.198

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

rewrite rule - trouble with question mark

     
6:03 pm on Jul 21, 2007 (gmt 0)

New User

10+ Year Member

joined:July 21, 2007
posts:6
votes: 0


Hi,

I am having trouble with my .htaccess rewrite rule, where I can't seem to properly escape the question mark in the url I want to redirect.

Here is my example:

RewriteRule ^report2\.html\?loc=wna_us_fl_cape_canaveral$

/surf-forecast/cape-canaveral-florida.html [R=301,L]

The problem area is the .html\?loc=... If I take away the questions mark then it works fine and the escape character doesn't seem to work in this example.

Any help here? Much appreciated.

6:14 pm on July 21, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Query strings are not part of a URL; They are data attached to a URL to be passed to the resource (e.g. script) at that URL.

You must use

RewriteCond %{QUERY_STRING} ^loc=wna_us_fl_cape_canaveral$ 

along with a URL pattern in the RewriteRule, to test (and/or back-reference) your query-string.

Jim

7:17 pm on July 21, 2007 (gmt 0)

New User

10+ Year Member

joined:July 21, 2007
posts: 6
votes: 0


I see.

this is what i did:

RewriteCond %{QUERY_STRING} ^loc=wna_us_fl_cape_canaveral$
RewriteRule ^report2\.html$ /surf-forecast/cape-canaveral-florida.html [R=301,L]

This does the redirect, however, the query string gets appended on to the new url. How do I get rid of the query string. Perhaps this is what you were referring to with the testing / back referencing? I'm not sure how to go about that.

7:24 pm on July 21, 2007 (gmt 0)

New User

10+ Year Member

joined:July 21, 2007
posts:6
votes: 0


I found an answer to my question about removing the appended query string.

I put a "?" on the end of the url i was redirecting to, and this removed the query string from the new(redirected) url.

7:54 pm on July 21, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 22, 2003
posts:53
votes: 0


cant believe I just found that out, used RewriteRule ages ago when doing a site and all/most old urls had? & = in them, when redirected they still worked but were ugly as they appended that cod tot he end of the url, and now I find out all I had to do was add a? to the end of the destination url

well at least I know for next time (very soon actualy), thanks for the info

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members