【问题标题】:redirect from http to https and without www to www does not work correctly从 http 重定向到 https 并且没有 www 到 www 无法正常工作
【发布时间】:2016-08-11 02:58:58
【问题描述】:

我有以下 .htaccess 文件,但网站的某些部分无需“www”即可访问。如何更改我的 htaccess,以便我的网站的所有 url 只能通过“www”访问?

<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

希望有人能帮忙?

编辑:当我在其他帖子中使用此规则时:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.yourdomain.com%{REQUEST_URI} [R=301,L,NE]

问题没有解决。所有页面都可以使用 https 和 www 正常工作。但是 wp-content/uploads 文件夹中的所有图像仍然可以在没有 www 和 http 的情况下访问。该网站是 hochzeitshaus-leipzig.de

我没有看到错误...

【问题讨论】:

  • wp-contentwp-content/uploads 是否也有 .htaccess?
  • 是的,这个代码还有另一个 htaccess:# BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 重写规则。 /index.php [L] # 结束 WordPress
  • 我可以删除这个htaccess吗?
  • 根目录下的一个htaccess就够了
  • 好的,当我删除我工作的文件夹中的 htaccess 时。-) 我需要第二个 htaccess 吗?

标签: wordpress .htaccess


【解决方案1】:

检查 RewriteCond

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]

【讨论】:

猜你喜欢
  • 2016-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-06
  • 2018-09-26
  • 2013-07-01
  • 2016-10-15
  • 2016-02-28
相关资源
最近更新 更多