1

I have a developer account and the setup is different from a typical host.

With this provider, each domain is allocated an app. 4 domains:

https://example.com https://www.example.com http://example.com http://www.example.com

The chosen "main" domain is the top one, https://example.com. So, in my host login panel, I have allocated the website "app" to https://example.com while the remaining 3 are allocated "redirect" apps.

For the non ssl http domains I have used:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

The purpose of this is to just redirect to ssl. This seems to work fine.

Then, for the www version, which I'd like to redirect to non www version, I have used:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

Does not work. But, in additon to figuring that out, what I'd really like is to have the 3 domain variants all served by the same .htaccess file with 2 purposes: redirect to ssl and to non www version. Is this possible?

4

1 回答 1

1

Yes, you can use the [OR] flag to qualify an either/or:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

You can have that in a single htaccess file that all 4 app spaces use.

于 2013-10-01T21:54:05.227 回答