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 |
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 domain.com, and redirect with 301 to www.domain.com. But when URL is domain.com/city/Sydney.php for example, it wouldn't redirect to www.domain.com/city/Sydney.php. Any suggestion!!
My current rewrite rule is RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L] thanks |
did you remove the "blank space" in the file name
"it looked for %20.php in city " "%20" is not a file name http://www.blooberry.com/indexdot/ht...rlencoding.htm |
Hi John,
Yep %20 is not the file name, just the space. So when the request url is www.domain.com/%20 ( 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 www.domain.com/Sydney.php , it will redirect to www.domain.com/city/Sydney.php , since Sydney.php is not in the root directory. In this case with %20 (space), it was trying to return www.domain.com/city/ .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. Cheers |
All times are GMT -5. The time now is 09:31 PM. |