我如何将.htaccess文件写入https://www.domain.com 例如:
domain.com => https://www.domain.com
www.domain.com => https://www.domain.com
https://domain.com => https://www.domain.com
http://www.domain.com => https://www.domain.com
这是我的htaccess:
# Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php
<IfModule mod_rewrite.c>
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
Options +Indexes
RewriteEngine On
RewriteCond %{http_host} ^mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME}.php -f
</IfModule>
# BEGIN WordPress
# END WordPress
我添加下一个代码:
<IfModule mod_rewrite.c>
# add https to domain.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
但我的域名仍然是www.domain.com而不是https://www.domain.com。 我应该改变什么?
非常感谢。答案 0 :(得分:0)
您应该做的就是将以下内容添加到http.conf
或.htaccess
:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
如果你编辑http.conf
,你应该在之后重新启动Apache:
service httpd restart
答案 1 :(得分:0)
通过httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在.htaccess
目录下的DOCUMENT_ROOT
中:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [L,R=301]