编写我的.htaccess

时间:2018-04-05 22:51:09

标签: php html .htaccess

我有一个页面,我目前正在尝试编写一个合适的.htaccess文件。

目前我有这段代码:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

所以这样做很好,但是我希望它用“' www'在前面。

我已经尝试过了:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

但它显然不会像那样工作。

我很高兴,如果你可以帮助我, 非常感谢。

1 个答案:

答案 0 :(得分:-1)

你可以尝试这样的事情。

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

或者

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]