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

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

Apache Web Server Forum

htaccess won't catch rewrite URL's that include a % character
how to make htaccess URL's that include a % character

Msg#: 4260794 posted 9:09 pm on Jan 31, 2011 (gmt 0)

some of my URL's include query lines and some sites link to them replacing the ?, = and + with their % encoding, which means an URL like this:


ends up like this:

My server doesn't find them and Google marks them as 404.

No matter how I try to catch them for redirection, it doesn't work. I tried these, without success:

RewriteRule ^exampleurl.php\%3Fitem\%3D(.*)\%2B(.*)$ /index.php [R=301,L]

RewriteRule ^exampleurl.php%3Fitem%3D(.*)%2B(.*)$ /index.php [R=301,L]

RewriteCond %{QUERY_STRING} ^item%3D(.*)$
RewriteRule ... as usual...

Of course the last one can't work since the "?" isn't even in the url...

Does anybody have a solution? I've search the forums but don't even know exactly how to refer to the % special characters in my search terms.

[edited by: jdMorgan at 7:20 pm (utc) on Feb 7, 2011]
[edit reason] example.com to suppress auto-linking. [/edit]


Receptional Andy

Msg#: 4260794 posted 10:43 am on Feb 1, 2011 (gmt 0)

You don't actually need any escaping other than for the equals symbol which is an operator. Additionally, if you're trying to match the part after the question mark, you must use a rewrite condition, e.g.

RewriteCond %{QUERY_STRING} ^item=this\+item
RewriteRule .* http://www.example.com/newurl.php [R=301,L]


WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Msg#: 4260794 posted 11:10 am on Feb 1, 2011 (gmt 0)

The above code will re-append the original query string.

To suppress that action add a question mark to the target URL.

If you want to "re-build" the query string with ? and = the code will be a LOT more complex.

There was a similar question a few weeks ago. That other thread contains a large amount of example code.


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

Msg#: 4260794 posted 7:24 pm on Feb 7, 2011 (gmt 0)

# Replace encoded "?" characters with literal "?" characters
RewriteCond %{THE_REQUEST ^[A-Z]+\ /([^%]*)\%(25)*3[fF]([^\ ]+)\ HTTP?
RewriteRule ^ http://www.example.com/%1?%3 [R=301,L]

The (25)*3[fF] allows for multiply-encoded question marks, encoded using upper- or lower-case "F".


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