简体   繁体   English

WordPress 301 重定向所有页面

[英]WordPress 301 redirect for all pages

I have a WordPress site for which I wish to force all pages to go to https and non-www我有一个 WordPress 站点,我希望将所有页面强制到 go 到 https 和非 www

So I want following redirection.所以我想要跟随重定向。

http://example.com --> https://example.com http://example.com --> https://example.Z4D236D9A2D102C50FE6AD1C50DAB
www.example.com --> https://example.com www.example.com --> https://example.com
http://example.com/abcd --> https://example.com/abcd http://example.com/abcd --> https://example.com/abcd
www.example.com/abcd --> https://example.com/abcd www.example.com/abcd --> https://example.com/abcd

I have following code in my .htaccess file我的 .htaccess 文件中有以下代码

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteEngine On
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

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


The problem is that it only redirects the home page correctly, for inner pages I get a Page not Found/Site cannot be reached error.问题是它只正确重定向主页,对于内页我得到一个页面未找到/站点无法访问错误。

Try this:尝试这个:

RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]

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

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