Welcome to WebmasterWorld Guest from 54.167.177.207

Forum Moderators: Ocean10000 & incrediBILL & phranque

% in url breaks .htaccess redirect?

wildcard % in url breaks .htaccess redirect?

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

5+ Year Member



Works
http://www.example.com/City/kw=some+keyword;campaign=6;ad=123;creative=3;placement=cnn;somevar=1

Does NOT Work:
http://www.example.com/City/kw=some+keyword;campaign=6;ad=123;creative=3;placement=http%3a%2f%2fwww.cnn.com%2f;somevar=1

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:

http://www.example.com/City/?kw=some+keyword&campaign=6&ad=123&creative=3

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 Jun 8, 2009 (gmt 0)

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



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.

Jim

 

Featured Threads

Hot Threads This Week

Hot Threads This Month