Achilles
Achilles

Reputation: 91

Regex expression in apache configuration file

I need to make sure that if a user hits "//" instead of "/", it should be handled by regex in apache config for some urls. For ex -

"http://www.mysite.com//home/index.jsp" URL should be redirected or treated as "http://www.mysite.com/home/index.jsp"

Can you please throw some light on what regex I should be using in the apache config to make sure this works perfectly?

Upvotes: 1

Views: 431

Answers (1)

Joey
Joey

Reputation: 354536

Taken from this answer:

If you're using Apache with mod_rewrite, there is a pretty simple fix:

# remove multiple slashes anywhere in url 
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ 
RewriteRule . %1/%2 [R=301,L] 

This will issue a HTTP 301 Moved Permanently redirect so that any double slashes are stripped out of the URL.

Upvotes: 1

Related Questions