【问题标题】:Wordpress Force Redirect to https some page not workingWordpress 强制重定向到 https 某些页面不起作用
【发布时间】:2019-09-10 06:34:36
【问题描述】:

如果用户单击其他 URL 格式,我希望我的网站始终显示“https://www.example.com”,格式必须直接指向带有 www 和 https 的完整 URL

我尝试强制我的 WordPress 网站始终在 .htaccess 文件中使用 https,我发现它可以重定向到 https,除了一些 URL,例如“http://example.com/category

但是,如果我在结束 URL 处输入“/”,例如“http://example.com/category/”,重定向规则就起作用了!!

我的 .htaccess 代码在下面,我的网站在 cloudways 上运行

# BEGIN WordPress
   <IfModule mod_rewrite.c>
   RewriteEngine On

   RewriteCond %{HTTP_HOST} ^example.com [NC]
   RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
   RewriteCond %{HTTP:X-Forwarded-Proto} !https
   RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

   # END WordPress

【问题讨论】:

    标签: wordpress .htaccess https


    【解决方案1】:

    将以下内容添加到 .htaccess 文件的顶部。

    RewriteEngine on
    RewriteCond %{HTTPS} !on [OR]
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]
    

    https://wordpress.org/support/topic/forcing-http-to-https-and-non-www-to-www/

    【讨论】:

    • 感谢您的评论,试试您的代码,我收到许多重定向连接错误
    【解决方案2】:

    在这种情况下,我强烈建议不要在 .htaccess 文件中使用重定向,而是简单地定义 Wordpress 的 URL 地址,您可以从设置 URL 地址的后端设置中设置并包含它在“wp-config.php”中:

    将这两行添加到您的 wp-config.php,其中“example.com”是您网站的正确位置。

    定义('WP_HOME', 'https://www.example.com');

    define('WP_SITEURL', 'https://www.example.com');

    如下文所述: https://wordpress.org/support/article/changing-the-site-url/

    通过这样执行,您将摆脱重定向过程并协助“优化”网站。此外,谷歌和其他搜索引擎将使用“HTTPS”缓存默认地址,从而减少重定向,即减少网站的加载时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-24
      • 2014-03-19
      • 2015-08-31
      • 2018-08-31
      • 2018-01-31
      • 1970-01-01
      • 2021-10-18
      • 2018-10-09
      相关资源
      最近更新 更多