重定向字preSS网站到https的作品,但不是网页和帖子重定向、不是、网页、帖子

2023-09-02 11:43:19 作者:蝴蝶爲花醉、花卻自枯萎

我想安装HTTPS统治的.htaccess 文件,以便任何人访问我的网站被重定向到https,实现这一点,这是我的 htaccess的文件看起来像

I am trying to setup https rule in .htaccess file so whoever access my website gets redirected to https and to achieve this, this is how my htaccess file looks like

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteRule ^$ https://www.domain.com/%{REQUEST_URI} [R,L]
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

以上工作正常,我怎么主页,但如果我直接访问一个页面 domain.com/page 然后不重定向到https

The above works fine how home page but if i access a page directly domain.com/page then i dont get redirected to https

有人能告诉我我在想什么?

Can someone please tell me what am i missing?

推荐答案

更​​改重写规则

RewriteRule ^ https://www.domain.com/%{REQUEST_URI} [R,L]

的通知,也没有 $ ^ ,这是有效的,说明重定向,但只有在没有目录的路径信息在IE中重定向URL根 / 只请求。

Notice, there's no $ after ^, which was effectively stating that redirect but only if no directory path information is found i.e. redirect root URL / requests only.