【问题标题】:htaccess rewrite for domains using Wordpress with non-www and httpshtaccess 使用带有非 www 和 https 的 Wordpress 重写域
【发布时间】:2017-01-15 22:47:00
【问题描述】:

我正在寻找适用于使用非 www 和 https (SLL) 以及 Wordpress 的域的 .htaccess 配置**

在堆栈溢出和数百种组合上花费了数小时后,我还没有找到一个可以满足我所有需要的 htaccess 文件。

此 htaccess 文件必须执行以下操作:

  1. www 改写为非 www
  2. http 重写为 https
  3. 保留 URI 字符串(您网站上的 url 部分)
  4. 启用 wordpress 以处理漂亮的永久链接。
  • http://www.示例 .com --> https:// 示例 .com
  • https://www. example.com --> https://example.com
  • http://example.com --> https://example.com
  • https://example.com --> https://example.com(必须忽略)
  • http://www.例如.com/foo.html --> https://example.com/foo.html
  • https://www.例如.com/foo.html --> https://example.com/foo.html
  • http://example.com/foo.html --> https://example.com/foo.html
  • https://example.com/foo.html --> https://example.com/foo.html (必须忽略)

【问题讨论】:

  • 如果您想发布信息,请写一个问题,并选中表格底部的Answer your own question 框。

标签: .htaccess redirect https uri


【解决方案1】:

我终于自己解决了问题

将以下代码添加到您的 .htaccess 文件中。

    # BEGIN Rewrite so the site works with www and without.
    RewriteEngine On
    RewriteCond %{HTTPS_HOST} ^www\.example\.com$
    RewriteRule ^(.*)$ https://example.com/$1 [R=301]
    # END Rewrite so the site works with www and without.

    # 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]
    </IfModule>
    # END WordPress

附言。它也可能适用于使用 www 的网站。但我还没有测试过。

希望这对某人有所帮助! :-)

【讨论】:

    猜你喜欢
    • 2014-12-16
    • 2015-01-10
    • 2012-10-17
    • 1970-01-01
    • 2021-07-31
    • 2018-11-12
    • 2014-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多