dklynn,
As you are aware, encoded characters display as %{two character hexadecimal} in a URL. These are to be avoided, obviously, as they make for an UGLY URL! Then, one has to ask WHY you’d encode a / (%2f) in a URI!
I put product names in the URL for SEO reasons, and some product names have a “/” in them and when URL encoded they become a %2f.
Also, the %2f might be necessary for an ajax api that requires a URL to be sent within another URL.
so the link would be:
<a href=“/categories/product-name%2fwith-a-slash”>Product Name / With A Slash</a>
My php script checks the database for a product with that name (properly escaping the value of course) to show the appropriate page with product details.
Okay, after all that, it really SHOULD redirect as Apache decodes the character before processing with mod_rewrite. For instance, %20 (a space) is matched with [\ ] in regex.
If this is true, than there is a bug.
Like I said in my original post, simply putting a % in the URL stops the redirect from happening. There is no reason that it should not redirect.
RewriteRule ^categories/(.)\.html(.) /$1/$2 [R=301,L]
(.*) means anything, so ‘string’ and ‘str%ing’ should both redirect, but the second one does not!
Finally, PLEASE, for your own sake, learn regex! The EVERYTHING atom, (.*), will get you in more trouble than any other bit of regex there is! Having it in your regex TWICE can only get you in TWICE the trouble (actually, the second one will only match the null string as it CANNOT match anything in the %{QUERY_STRING} variable - you MUST use a RewriteCond for that!
The reason is that the second B[/B] does actually does allow URLs to redirect with a query string.
This url: website.com/category/test.html?name=frank
redirects to
website.com/test/?name=frank
Is there any reason not to do this?
I prefer this
RewriteRule ^categories/(.)\.html(.) /$1/$2 [R=301,L]
rather than using the ugly:
RewriteCond %{QUERY_STRING} ^(.)$ [NC]
RewriteRule ^categories/(.)\.html /$1/%1 [R=301,L]
(by the way, I know about regexp, at least within php. it is htaccess that throws me for a loop.)
Thanks for the response, unfortunately it was not helpful in solving this problem.
So… anyone have an answer, or work-around that allows a URL with a percent symbol to redirect?