LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-09-2011, 06:01 AM   #1
jnyunt
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, 08:12 PM   #2
jnyunt
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 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

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

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
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

Last edited by John VV; 08-09-2011 at 10:43 PM.
 
Old 08-09-2011, 10:56 PM   #4
jnyunt
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 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
 
  


Reply



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 09:12 PM
URL rewrite rule not working... vikram_cvk Linux - Software 1 12-03-2008 02:14 AM
Apache rewrite rule help - dynamic url to static page DukeLeto Linux - Software 3 11-12-2008 11:26 AM
rewrite rule base url apache2 sinister1 Linux - Software 3 11-23-2007 10:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:25 PM.

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