Digital Point Forums
Quick Collect

Go Back   Digital Point Forums > Design & Development > Site & Server Administration > Apache
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Feb 22nd 2005, 8:21 am
chachi's Avatar
chachi chachi is offline
The other Jason
 
Join Date: May 2004
Location: SF, CA
Posts: 1,600
chachi has a spectacular aura aboutchachi has a spectacular aura about
How to 301 Redirect URL with %20 In It

Anyone know how to redirect a url with spaces in them. I get more and more 404 pages because of urls with %20 after them these days. I can't seem to get them to work in my .htaccess file.
Reply With Quote
  #2  
Old Feb 22nd 2005, 11:07 am
nullbit nullbit is offline
Hand of A'dal
 
Join Date: Feb 2005
Posts: 489
nullbit is on a distinguished road
Untested (updated: tested, does work):
Code:
RewriteEngine on

RewriteRule [^\s]+ $0?%{QUERY_STRING}
Tell me if it does not work. This will just remove the spaces from the url, you don't really need to perform a redirect, unless you are worried about it being indexed as duplicate content?
__________________
SEO Tool - The killer search engine optimization tool. No. Really.
The Search Engine Experiment - Discover if Google really giving you the most relevant results
- No recip required.

Last edited by nullbit; Feb 22nd 2005 at 11:15 am.
Reply With Quote
  #3  
Old Feb 22nd 2005, 12:04 pm
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
Quote:
Originally Posted by chachi
Anyone know how to redirect a url with spaces in them. I get more and more 404 pages because of urls with %20 after them these days. I can't seem to get them to work in my .htaccess file.
Browsers usualy strip the whitespace at the end of the URL. Look at the user-agent strings in the log to figure out who's requesting these URLs.

J.D.
Reply With Quote
  #4  
Old Feb 22nd 2005, 12:17 pm
nullbit nullbit is offline
Hand of A'dal
 
Join Date: Feb 2005
Posts: 489
nullbit is on a distinguished road
Quote:
Originally Posted by J.D.
Browsers usualy strip the whitespace at the end of the URL. Look at the user-agent strings in the log to figure out who's requesting these URLs.

J.D.
I was thinking this. Chances are it might be a good thing to not serve this user agent, since it's probably not a regular user, most likely some badly coded scraper.
__________________
SEO Tool - The killer search engine optimization tool. No. Really.
The Search Engine Experiment - Discover if Google really giving you the most relevant results
- No recip required.
Reply With Quote
  #5  
Old Feb 22nd 2005, 1:35 pm
chachi's Avatar
chachi chachi is offline
The other Jason
 
Join Date: May 2004
Location: SF, CA
Posts: 1,600
chachi has a spectacular aura aboutchachi has a spectacular aura about
I am not really doing it for browsers as much as I am for bots. Gbot in particular does not seem to want to remove the spaces.

That rewrite removed the spaces, but it also made it so that my style sheets were not used by FF
Reply With Quote
  #6  
Old Feb 22nd 2005, 1:36 pm
nullbit nullbit is offline
Hand of A'dal
 
Join Date: Feb 2005
Posts: 489
nullbit is on a distinguished road
Do your CSS files have spaces in them? If yes, then the RewriteRule, will need a small revision.
__________________
SEO Tool - The killer search engine optimization tool. No. Really.
The Search Engine Experiment - Discover if Google really giving you the most relevant results
- No recip required.
Reply With Quote
  #7  
Old Feb 22nd 2005, 1:47 pm
chachi's Avatar
chachi chachi is offline
The other Jason
 
Join Date: May 2004
Location: SF, CA
Posts: 1,600
chachi has a spectacular aura aboutchachi has a spectacular aura about
no spaces in the file names

<edit>Ahh, but if I turn the RewriteEngine off, it works.

But, I really would like to do a 301 as these are links coming from other sites, so if anyone knows how to do that I would love to hear how.
</edit>
Reply With Quote
  #8  
Old Feb 22nd 2005, 2:10 pm
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
Can you post a sample URL/user agent from the log?

J.D.
Reply With Quote
  #9  
Old Feb 22nd 2005, 2:15 pm
nullbit nullbit is offline
Hand of A'dal
 
Join Date: Feb 2005
Posts: 489
nullbit is on a distinguished road
A 301 using .htaccess is simple:

redirect 301 /source.htm /destination.htm

Somehow you need to combine that with the rewrite module to capture & redirect all pages with trailing spaces. Right now, I can't think how you would do this.

Edit: Of course, if the number of URLs is short, you could just add them all using the above sample.
__________________
SEO Tool - The killer search engine optimization tool. No. Really.
The Search Engine Experiment - Discover if Google really giving you the most relevant results
- No recip required.
Reply With Quote
  #10  
Old Feb 22nd 2005, 2:38 pm
chachi's Avatar
chachi chachi is offline
The other Jason
 
Join Date: May 2004
Location: SF, CA
Posts: 1,600
chachi has a spectacular aura aboutchachi has a spectacular aura about
I know how to do a 301 in .htaccess. But, it is not working with %20 in the url
Reply With Quote
  #11  
Old Feb 22nd 2005, 2:46 pm
nullbit nullbit is offline
Hand of A'dal
 
Join Date: Feb 2005
Posts: 489
nullbit is on a distinguished road
Quote:
Originally Posted by chachi
I know how to do a 301 in .htaccess. But, it is not working with %20 in the url
Try replacing every occurance of %20 with a backslash (to escape the space):

Example:
Code:
redirect 301 /source.htm\ \ \  /destination.htm
Remember to include an unescaped space at the end of the source string.

Also using literal spaces, and quoting the source string might work:

Example:
Code:
redirect 301 "/source.htm   " /destination.htm
__________________
SEO Tool - The killer search engine optimization tool. No. Really.
The Search Engine Experiment - Discover if Google really giving you the most relevant results
- No recip required.
Reply With Quote
  #12  
Old Feb 22nd 2005, 5:52 pm
chachi's Avatar
chachi chachi is offline
The other Jason
 
Join Date: May 2004
Location: SF, CA
Posts: 1,600
chachi has a spectacular aura aboutchachi has a spectacular aura about
ahh, there we go. Used the quotes as in the second example and it works perfectly. Thanks for your help.
Reply With Quote
  #13  
Old Feb 22nd 2005, 7:35 pm
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
Quote:
Originally Posted by nullbit
Code:
redirect 301 "/source.htm   " /destination.htm
If you want to get rid of one or more spaces, you could use this:

Code:
RedirectMatch 301 "^(.+?) +$" $1
J.D.
Reply With Quote
  #14  
Old Feb 23rd 2005, 5:37 am
poit poit is offline
Peon
 
Join Date: Feb 2005
Posts: 18
poit is on a distinguished road
Heck that is interesting.
Thanks for that
Reply With Quote
  #15  
Old Feb 23rd 2005, 7:22 am
TechEvangelist's Avatar
TechEvangelist TechEvangelist is offline
Twilight Vanquisher
 
Join Date: Apr 2004
Location: Stupid question. At my PC.
Posts: 874
TechEvangelist is a splendid one to beholdTechEvangelist is a splendid one to beholdTechEvangelist is a splendid one to beholdTechEvangelist is a splendid one to beholdTechEvangelist is a splendid one to beholdTechEvangelist is a splendid one to beholdTechEvangelist is a splendid one to beholdTechEvangelist is a splendid one to behold
One piece was missing in this thread. How were the spaces getting tacked to the end of the URLs? I've never seen a hex space %20 tacked onto the end of a URL, although it is common when someone uses a space in a file name.

How is it gettin in there?
Reply With Quote
  #16  
Old Feb 23rd 2005, 7:41 am
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
Quote:
Originally Posted by TechEvangelist
How is it gettin in there?
I'd be interested to hear about this as well. chachi, can you post a couple of user agents (from your logs) that append spaces to URLs?

J.D.
Reply With Quote
Reply

Bookmarks

Thread Tools

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
redirect in htaccess hurricane_sh Apache 6 Jun 7th 2006 3:31 am
Craaaaaazy redirect - HELP loewydesign Co-op Advertising Network 1 Dec 16th 2004 7:31 pm
cpanel and redirect vagrant Site & Server Administration 2 Oct 14th 2004 6:15 am
Redirect phpBB2 forums and topics to IPB bobafind Apache 1 Sep 16th 2004 10:37 am
DNS Redirect pk_synths Apache 10 Mar 26th 2004 11:15 am


All times are GMT -8. The time now is 10:27 pm.