Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Redirecting double-slash ("//") URLs to single-slash ("/") URLs

Question posted by: Guy Macon (Guest) on July 3rd, 2008 10:45 PM



As a personal learning experience with limited practical use,
I have been doing some experiments with using .htaccess to
redirect mis-typed URLs to a preferred canonical form. I have
set up a test page at [ http://www.guymacon.org/test.html ]
to show the results of my testing.

Most of the URLs redirect as I want them to do, but the three
URLS (with "//" instead of "/") in bold do not redirect.

I have searched the web and have not found a single website
that redirects *all* "//" URLs to "/" URLs.

Given the rarity of this error, a solution that causes a 404
error rather than a 301 redirect would be fine with me, but I
haven't seen any websites that manage that one either.

Any suggestions for things to try would be most welcome.
Thanks!

[ http://www.guymacon.org/test.html ]

--
Guy Macon
<http://www.GuyMacon.com/>

Steve's Avatar
Steve
Guest
n/a Posts
July 4th, 2008
01:15 AM
#2

Re: Redirecting double-slash ("//") URLs to single-slash ("/") URLs
Guy Macon wrote:
Quote:
As a personal learning experience with limited practical use,
I have been doing some experiments with using .htaccess to
redirect mis-typed URLs to a preferred canonical form. I have
set up a test page at [ http://www.guymacon.org/test.html ]
to show the results of my testing.
>
Most of the URLs redirect as I want them to do, but the three
URLS (with "//" instead of "/") in bold do not redirect.
>
I have searched the web and have not found a single website
that redirects *all* "//" URLs to "/" URLs.
>
Given the rarity of this error, a solution that causes a 404
error rather than a 301 redirect would be fine with me, but I
haven't seen any websites that manage that one either.
>
Any suggestions for things to try would be most welcome.
Thanks!
>
[ http://www.guymacon.org/test.html ]
>


Haven't tested but this guy's approach looks good on paper if you have
access to PHP (probably easy enough to replicate in any server-side
language):

http://groups.google.com/group/alt....a0f7baad24c74dc

Dunno. It's a nearly 3-year old thread you were actually involved in,
so perhaps it doesn't work.

Steve's Avatar
Steve
Guest
n/a Posts
July 4th, 2008
01:15 AM
#3

Re: Redirecting double-slash ("//") URLs to single-slash ("/") URLs
Steve wrote:
Quote:
Dunno. It's a nearly 3-year old thread you were actually involved in,
so perhaps it doesn't work.


.... and by that, I mean perhaps you already tried it. Just re-read and
that sentence came off as an insult, which wasn't my intent.

Guy Macon's Avatar
Guy Macon
Guest
n/a Posts
July 4th, 2008
09:26 AM
#4

Re: Redirecting double-slash ("//") URLs to single-slash ("/") URLs



Steve wrote:
Quote:
>Haven't tested but this guy's approach looks good on paper if you have
>access to PHP (probably easy enough to replicate in any server-side
>language):
>
>http://groups.google.com/group/alt....a0f7baad24c74dc


Thanks!

I put it in my .htaccess -- you can see the results by clicking on
the three bold URLs at [ http://www.guymacon.org/test.html ].


--
Guy Macon
<http://www.GuyMacon.com/>


Guy Macon's Avatar
Guy Macon
Guest
n/a Posts
July 6th, 2008
08:45 AM
#5

Re: Redirecting double-slash ("//") URLs to single-slash ("/") URLs



Guy Macon wrote:
Quote:
>
>Steve wrote:
>
Quote:
>>Haven't tested but this guy's approach looks good on paper if you have
>>access to PHP (probably easy enough to replicate in any server-side
>>language):
>>
>>http://groups.google.com/group/alt....a0f7baad24c74dc

>
>Thanks!
>
>I put it in my .htaccess -- you can see the results by clicking on
>the three bold URLs at [ http://www.guymacon.org/test.html ].


I am now removing it again. The result was, as I expected, that
It did not handle the test cases in bold at
[ http://www.guymacon.org/test.html ].
As far as I can tell, no website anywhere is able to handle all
of those test cases using .htaccess -- I am convinced that Apache
converts some "//"s to "/"s prior to feeding user request to
mod_rewrite.


--
Guy Macon
<http://www.GuyMacon.com/>


 
Not the answer you were looking for? Post your question . . .
189,798 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors