Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

% in url breaks .htaccess redirect?

wildcard % in url breaks .htaccess redirect?

10:18 am on Jun 8, 2009 (gmt 0)

New User

5+ Year Member

joined:June 4, 2008
posts: 19
votes: 0


Does NOT Work:

RewriteEngine on
RewriteRule ^(.*)/kw=(.*) start_f.php?tag=$1&redir=1&string=$2 [L,NC,QSA]

Whenever I have a % character anywhere in my url, my .htaccess redirect doesn't seem to work.

The reason I'm using the stupid var=value;var2=value2;etc. format is because I also had an issue getting THIS to work:


What I wanted to do here is simply catch the 'City' with the .htaccess redirect and just pass along the other values with QSA (Query String Attach) like so;

RewriteRule ^(.*)/\?kw=.* start_f.php?tag=$1&redir=1 [L,NC,QSA]

The reason I use the ?kw= as the cut off is because of other url formats on the site. As said, I'm trying to use QSA to pass on all the _GET values in the url so I don't need to capture whatever is after kw=

The problem is that the latter also isn't working. Am I escaping the question mark incorrectly or does .htaccess not work like I'm trying to use it for Query Strings?

I don't care which format I use as long as I can get one of them to work properly and WITH the ability to pass a url encoded string/website address as part of the data.

[edited by: jdMorgan at 1:15 pm (utc) on June 8, 2009]
[edit reason] example.com [/edit]

1:06 pm on June 8, 2009 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
votes: 0

See mod_rewrite documentation, RewriteRule, [NE] (NoEscape) flag for a possible solution.

Your URIs should be designed to contain only allowed characters in each part, and note that query strings are not considered to be part of a URL but rather data attached to a URL, and therefore have different character-usage and character-encoding requirements. This allows more characters to be used freely in query strings, but also means that if you intend to rewrite from a dynamic to a static URL, you may run into trouble. See RFC2396 - Uniform Resource Identifiers (URI): Generic Syntax [faqs.org]

The reason your attempted dynamic URL rewrite rule failed is also because the query string is not part of the URL. You need to use a RewriteCond to examine the %{QUERY_STRING} environment variable, because RewriteRule cannot 'see' the query string.