Reputation: 31
I hope someone can help me with a mod_rewrite rule, that works apart from adding trailing slashes.
This is the rule
<IfModule rewrite_module>
Options Indexes FollowSymLinks +IncludesNOEXEC
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.org$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.org/$1 [L,R=301]
</IfModule>
The purpose is to rewrite the URL mydomain.org in the form www.mydomain.org
This works. but then www.mydomain.org// shows in the browser address bar. Checking the rewrite log shows that the // is explicitly created by the rule
Questions are:
Upvotes: 3
Views: 411
Reputation: 1539
RewriteRule ^/?(.*)$ http://www.mydomain.org/$1 [L,R=301]
. That /?
is what does the trick.Upvotes: 1
Reputation: 107736
Most servers ignore the double slash and treat it as a single. See for example this question (double-slash) https://stackoverflow.com//questions/13027041
To fix your RewriteRule
, I believe you just need to change it to
RewriteRule ^/?(.*)$ http://www.mydomain.org/$1 [L,R=301]
The /?
part makes it optional (root access), and if it is found, it gets stripped since it is not part of the captured (.*)
section.
Upvotes: 1