简体   繁体   English

重定向到https:// www。 当没有子域而只有https:时

[英]Redirect to https://www. when there is no subdomain and just https: when there is

When someone enters on http:// (non-secure), there are two possible scenarios. 当有人输入http:// (非安全)时,有两种可能的情况。 I'd like to program an .htaccess file to account for both in the following ways: 我想通过以下方式对.htaccess文件进行编程以解决这两个问题:

1)They do not use a subdomain. 1)他们不使用子域。

Solution: redirect to https://www. 解决方案:重定向到https://www. + remaining URL. +剩余网址。

2) They use either http://www. 2)他们使用http://www. or http://subdomain. http://subdomain.

Solution: redirect to https://subdomain OR https://www. 解决方案:重定向到https://subdomainhttps://www. (whichever used) + remaining URL. (以使用者为准)+剩余网址。

How can I solve this within my .htaccess file? 如何在.htaccess文件中解决此问题?

Here is my current file: 这是我当前的文件:

 RewriteEngine on
 RewriteCond $1 !^(index\.php|images|css|js|font|uploads|robots\.txt)
 RewriteRule ^(.*)$ /index.php/$1 [L]

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory: 通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在DOCUMENT_ROOT目录下的.htaccess

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# redirect to https://www. + remaining URL.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# They use either http://www. or http://subdomain.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM