Reputation: 2799
I have the following HTTP address:
http://www.example.com/
but my HTTPS address has a subdomain and no www, like this:
https://secure.example.com/
I tried the following rule:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://secure.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Which sent me to:
https://secure.www.example.com/
How can I force HTTPS in this situation? As I need the www removed.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Upvotes: 1
Views: 55
Reputation: 41219
This should be your complete htaccess :
RewriteEngine On
RewriteBase /
#1--Redirect "http://domain to "https://secure"
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://secure.domain.com%{REQUEST_URI} [L,R=301]
#2--wp rules--#
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Upvotes: 1
Reputation: 1612
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://secure.example.com/$1 [L,R=301]
</IfModule>
OR
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://secure.example.com/$1 [R=301,L]
Both rules do exactly this: any non-https request is redirected to https://secure.example.com while preserving the whole url
Upvotes: 1