-   Linux - Server (
-   -   handling %20 in url with apache rewrite rule (

jnyunt 08-09-2011 06:01 AM

handling %20 in url with apache rewrite rule
Hi all ,
I googled and searched the forums, but can't find the answer. I implemented some rewriterule in .htaccess. but got unexpected results. So I need expert advice. I found crawl error in google webmaster, and shocked me that it was my home page was offending one. but after looking a bit further, that error url has %20 appended. I assume it is space symbol. my question is how do I rewrite that, so it is redirected to actual page.
Many thanks in advance

jnyunt 08-09-2011 08:12 PM

I think I got it working. In my .htaccess , I had RewriteRule ^([^/\.]+)$ city/$1.php , so when url had %20 appended, it looked for %20.php in city folder and threw error. Since I didn't really need that rewriterule and removed it, and it worked. Another problem I am facing is to rewrite url with www pre-fixed. I got it working when URL is just, and redirect with 301 to But when URL is for example, it wouldn't redirect to Any suggestion!!
My current rewrite rule is
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]


John VV 08-09-2011 10:41 PM

did you remove the "blank space" in the file name
"it looked for %20.php in city "

"%20" is not a file name

jnyunt 08-09-2011 10:56 PM

Hi John,
Yep %20 is not the file name, just the space. So when the request url is ( of course we couldn't see %20 in address bar, but I can see it in log), file not found error was returned. My initial setup was if request url is for example , it will redirect to , since Sydney.php is not in the root directory. In this case with %20 (space), it was trying to return .php (note the space before .php), and file not found error returned. catch my drift!!! Since I didn't really need to setup to redirect to city dir, I just removed the rewriterule and it worked.

All times are GMT -5. The time now is 07:42 AM.