I’d like to redirect web requests from example.org to www.example.org. I think I have the right rule, but it is adding two extra forward slashes:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.org [NC]
RewriteRule ^(.*)$ http://www.example.org/$1 [R=permanent,L]
The above would take me from example.org to www.example.org//
Is there a way to strip those trailing slashes? I tried the following variant, which strips those slashes but causes a redirect loop:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.org [NC]
RewriteRule ^(.*)$ http://www.example.org/$1 [R=permanent,L]
RewriteRule ^(.*)/$ /$1 [L,R=301]
How might I solve this?
Try adding
RewriteBase /right afterRewriteEngine on.If that doesn’t do it, change your rule to
RewriteRule ^/(.*)$ http://www.example.org/$1 [R=301,L]so you don’t capture the initial/.