max
max

Reputation: 331

.htaccess show 404 error if url has extra slashes

This is my URL structure

http://example.com/filename-.html

.htaccess

RewriteEngine on
RewriteBase /

RewriteRule ^filename-([0-9]+)\.html$ filename.php?id=$1 [L]
RewriteRule ^(.*)\.html$ $1.php [L]

ErrorDocument 404 /404.html

issue is that if there is a wrong url it doesn't go to 404 error page

Example wrong urls

http:///example.com/filename-18-bank/////-4.html

http://example.com//////listing-560.html

How can i tell .htaccess to redirect these url to 404 error document.

Upvotes: 3

Views: 1021

Answers (1)

anubhava
anubhava

Reputation: 785611

You can insert this rule just below RewriteBase line:

# send any request containing multiple / to 404
RewriteCond %{THE_REQUEST} //
RewriteRule ^ - [L,R=404]

Upvotes: 4

Related Questions