Reputation: 21
I'm trying to redirect the users of my website from HTTP to HTTPS.
Redirecting the base url http://www.example.com
to https://www.exmaple.com
work fine, but http://www.example.com/data
is redirected to https//www.example.comdata
without the /
between .com
and data
.
My full actual .htaccess is:
# BEGIN WpFastestCache
<IfModule mod_rewrite.c>
<IfModule mod_rewrite.c>
#RewriteEngine On
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I also have another rule in my virtualhost configuration:
Redirect / https://www.example.com
Upvotes: 2
Views: 268
Reputation: 45914
I have also another rule in virtualhost
Redirect / https://www.example.com
You are missing a trailing slash on the target URL in the Redirect
directive. So, it will end up redirecting /foo
to https://www.example.comfoo
. The Redirect
directive is prefix-matching; everything after the match is appended to the end of the target URL. This rule - in the VirtualHost - takes priority over the mod_rewrite directive in .htaccess
.
This should read:
Redirect / https://www.example.com/
If you notice in the network traffic, it is also prefixing the www
subdomain - which is also not present in the mod_rewrite directive.
If you have this Redirect
in the <VirtualHost>
container for port 80 (providing it covers both www and non-www requests) then you don't need the corresponding mod_rewrite directive in .htaccess
to redirect HTTP to HTTPS.
Upvotes: 2