通过 .htaccess 将 HTTPS 重定向到 HTTP

发布于 2024-09-19 03:46:11 字数 947 浏览 0 评论 0原文

我使用的是带有默认 .htaccess 的 WordPress,我需要将所有以 https:// 开头的网址重定向到 http://。我的服务器对 http 和 https 协议使用相同的文件夹... 这是我当前的 .htaccess:

# BEGIN WordPress <IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase 
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L] </IfModule> 
# END WordPress

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

它适用于 https://www.domain.com/ (重定向到 http://www.domain.com/),但它不适用于 https://www.domain.com/subpages/ (它还会重定向到 http://www.domain.com/)。

请问.htaccess 有什么问题吗?

谢谢

I'm using a WordPress with its default .htaccess and I need to redirect all urls starting with https:// to http://. My server is using the same folder for http and https protocols...
this is my current .htaccess:

# BEGIN WordPress <IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase 
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L] </IfModule> 
# END WordPress

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

It works fine for https://www.domain.com/ (redirects to http://www.domain.com/) but it doesn't work with https://www.domain.com/subpages/ (it also redirects to http://www.domain.com/).

Do you see any problem in .htaccess please?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

药祭#氼 2024-09-26 03:46:28

更改规则的顺序:

Options +FollowSymlinks

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{SERVER_PORT} ^443$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

    # BEGIN WordPress
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
</IfModule>

否则 WordPress 规则将捕获 URL 路径不为空的所有请求(即不仅仅是 /)。

Change the order of the rules:

Options +FollowSymlinks

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{SERVER_PORT} ^443$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

    # BEGIN WordPress
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
</IfModule>

Otherwise the WordPress rule will catch all request that’s URL path is not empty (i.e. not just /).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文