Remove multiple slashes

New to mod_rewrite? This is a good place to start.

Remove multiple slashes

Postby hm78 » Mon Sep 07, 2009 10:59 am

Examples:
  • example.org/
  • example.org//
  • example.org///
  • and so on

but also:
  • example.org/foobar//
  • example.org///foobar/
  • example.org///foobar///maria/peter///karl/
  • and so on


I think there is no situation, where you want/need more than one slash (or am I wrong?)

I found this solution (untested) in a german board:

Code: Select all
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(([^/\ ]+/)*)/+([^\ ]*)
RewriteRule ^ /%1%3 [L,R=301]


Is this okay? Could this be tweaked?
hm78
 
Posts: 17
Joined: Sun Mar 04, 2007 8:26 pm

Postby richardk » Mon Sep 07, 2009 12:37 pm

I don't think you can remove multiple slashes at the beginning.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /(.+/)?/+([^/\ ][^\ ]*)?\  [NC]
RewriteRule .* /%1%2 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 33 guests

cron