【发布时间】:2016-03-04 16:16:06
【问题描述】:
我有一个由插件生成的 .htaccess 文件。 它看起来像这样:
# BEGIN Far Future Expiration Plugin
<IfModule mod_expires.c>
ExpiresActive on
<FilesMatch "\.(gif|jpeg|jpg|png)$">
ExpiresDefault "access plus 168 hours"
</FilesMatch>
</IfModule>
# END Far Future Expiration Plugin
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
我需要实现 HTTPS 重定向。我尝试将以下内容添加到文件中,但它给了我一个 Too many redirects 错误。
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]
有什么建议吗?
【问题讨论】:
-
你只需要检查HTTPS,你不需要检查你的域是否有www。无论哪种方式,它都会重定向。
标签: php wordpress apache .htaccess https