0

I have a link http://mysite.com/myname which shows the profile page.. But if i use multiple

slashes like http://mysite.com///myname , it also shows the page..

My htaccess code is :

RewriteCond %{REQUEST_URI} ^/(\w+)/?$ [NC]

RewriteRule ^ profile.php?username=%1 [L,QSA]

How to avoid this problem?

Can someone help me?

anubhava
  • 761,203
  • 64
  • 569
  • 643
Micku
  • 550
  • 4
  • 9
  • 23
  • There is/are some bad rewrites in your `.htaccess`. – ThinkingMonkey Feb 08 '12 at 06:06
  • My htaccess code is : RewriteCond %{REQUEST_URI} ^/(\w+)/?$ [NC] RewriteRule ^ profile.php?username=%1 [L,QSA].. anything wrong? – Micku Feb 08 '12 at 07:48
  • @David : Ma problem is http://mysite.com///myname , it shows profile page even it has more than one slash after domain.... But i dont want to show profile page in this situation.. – Micku Feb 08 '12 at 08:01

3 Answers3

0

You can add the following if you want to ensure you're not treating multiple forward slashes as a single slash (which seems to be default Apache behavior and not any sort of bug or the result of a bad rewrite).

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^/\s]+\ HTTP

This should enforce a single-slash rule. Of course, this will also make it impossible to use anything like http://example.com/myname/edit, but that could be worked around using a more complicated regex if necessary.

Dan Ambrisco
  • 865
  • 7
  • 13
  • You should add this **before** your other RewriteConds. If doing that doesn't work, I'm out of explanations since either @anubhava's answer or my answer should work just fine. – Dan Ambrisco Feb 08 '12 at 20:16
0

Not sure why do you really want to block multiple slashes but here is a way to do that:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/{2,} [NC]
RewriteRule ^ - [L,F]

This will give Forbidden error is a URI has multiple slashes at start like ///myname will generate:

Forbidden

You don't have permission to access /myname on this server.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Hmm I posted that after properly testing it. Can you post your full .htaccess in your question (not in comments). – anubhava Feb 08 '12 at 08:53
0

Use this code to remove double slashes from the urls.

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} //
RewriteRule ^ $0 [R=302]

Change the 302 to 301 once you get it working.

Gerben
  • 16,747
  • 6
  • 37
  • 56