简体   繁体   English

htaccess重定向到SSL无效

[英]htaccess redirect to SSL not working

I used the following code in htaccess to redirect my inner page urls to https:// but they are not working. 我在htaccess中使用以下代码将我的内页网址重定向到https://,但它们无法正常工作。 When i go to my home page it redirects to https and then all inner pages do the same but if I access any inner page without using the secure url it doesn't redirect to secured. 当我转到主页时,它将重定向到https,然后所有内部页面都执行相同操作,但是,如果我不使用安全网址访问任何内部页面,则不会重定向到安全。

# 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]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# END WordPress
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>

Can anybody pls help? 有人可以帮忙吗?

Your rewrite conditions are too restrictive to match every possible wordpress URI. 您的重写条件过于严格,无法匹配每个可能的wordpress URI。 You might try redirecting based on server port instead. 您可以尝试基于服务器端口进行重定向。

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

I would venture to say try WP Force SSL plugin. 我敢说尝试WP Force SSL插件。 I've used this in the past to avoid making changes to my .htaccess file. 我过去曾使用过此方法,以避免对.htaccess文件进行更改。

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

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