1

我如何将 .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。我应该改变什么?

非常感谢。

4

2 回答 2

0

您应该做的就是将以下内容添加到http.conf.htaccess

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

如果您进行编辑http.conf,您应该在之后重新启动 Apache:

service httpd restart
于 2012-10-29T18:36:44.173 回答
0

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_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]
于 2012-10-29T18:45:35.247 回答