Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 08-09-2011, 07:01 AM   #1
LQ Newbie
Registered: Jun 2008
Posts: 26

Rep: Reputation: 0
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
Old 08-09-2011, 09:12 PM   #2
LQ Newbie
Registered: Jun 2008
Posts: 26

Original Poster
Rep: Reputation: 0
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]


Last edited by colucix; 01-31-2012 at 12:11 AM. Reason: Masked commercial link
Old 08-09-2011, 11:41 PM   #3
John VV
LQ Muse
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,511

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

"%20" is not a file name

Last edited by John VV; 08-09-2011 at 11:43 PM.
Old 08-09-2011, 11:56 PM   #4
LQ Newbie
Registered: Jun 2008
Posts: 26

Original Poster
Rep: Reputation: 0
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
rewrite rule for url change ravibhure Linux - Server 2 01-21-2010 10:12 PM
URL rewrite rule not working... vikram_cvk Linux - Software 1 12-03-2008 03:14 AM
Apache rewrite rule help - dynamic url to static page DukeLeto Linux - Software 3 11-12-2008 12:26 PM
rewrite rule base url apache2 sinister1 Linux - Software 3 11-23-2007 11:17 AM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:05 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration