【问题标题】:Force HTTP for non WWW and WWW对非 WWW 和 WWW 强制 HTTP
【发布时间】:2015-06-25 14:01:59
【问题描述】:

我试图强制用户使用 HTTP,我们不希望人们使用 HTTPS 访问我们的网站。下面的代码重定向到 http 就好了,有人使用 https://www 访问该网站,但不是 https://website

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

当人们输入没有 www 的 url 时,我如何让它做同样的事情?该网站正在通过 wordpress 强制使用 WWW。

谢谢!

RewriteEngine on
RewriteCond %{HTTPS} ^on
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##


# 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

# GZip Ninja Speed -- Starts here
# Do not write anything between "GZip Ninja Speed -- Starts" and "GZip Ninja Speed -- Ends"
# It will be deleted while uninstalling GZip Ninja Speed plugin
AddOutputFilterByType DEFLATE text/plain #GZip Ninja Speed
AddOutputFilterByType DEFLATE text/html #GZip Ninja Speed
AddOutputFilterByType DEFLATE text/xml #GZip Ninja Speed
AddOutputFilterByType DEFLATE text/css #GZip Ninja Speed
AddOutputFilterByType DEFLATE application/xml #GZip Ninja Speed
AddOutputFilterByType DEFLATE application/xhtml+xml #GZip Ninja Speed
AddOutputFilterByType DEFLATE application/rss+xml #GZip Ninja Speed
AddOutputFilterByType DEFLATE application/javascript #GZip Ninja Speed
AddOutputFilterByType DEFLATE application/x-javascript #GZip Ninja Speed
AddType x-font/otf .otf #GZip Ninja Speed
AddType x-font/ttf .ttf #GZip Ninja Speed
AddType x-font/eot .eot #GZip Ninja Speed
AddType x-font/woff .woff #GZip Ninja Speed
AddType image/x-icon .ico #GZip Ninja Speed
AddType image/png .png #GZip Ninja Speed
# GZip Ninja Speed -- Ends here

【问题讨论】:

  • @anubhava 我已将其设置为 example.com 如果我不允许使用 https,为什么还要在其中使用它?
  • @anubhava 一切都好。 htaccess 中除了 wordpress/gzip 之外唯一的其他项目是 301 重定向。

标签: .htaccess http mod-rewrite https


【解决方案1】:

你可以在你的 .htacess 中使用它

RewriteCond %{HTTPS} ^on
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

【讨论】:

  • 感谢@PanamaJack,但将其更改为帽子后,我收到此错误:此网页有重定向循环
  • 我认为您的 WP 可能会导致此问题。你可以在wordpress中关闭强制www吗?我注意到你提到了这一点。然后只需使用 .htaccess。
  • 嗯,是的,我在 wordpress 的后端将 url 设置为 example.com,但仍然出现重定向循环错误。
  • 我对规则做了一点小改动。请尝试更新后的规则。
  • 非常感谢您的帮助。我更改了代码,现在它没有将 https 重定向到 www 或非 www 的 http。我用我的整个 htaccess 文件更新了我的原始帖子。
猜你喜欢
  • 1970-01-01
  • 2017-12-04
  • 2011-06-17
  • 1970-01-01
  • 1970-01-01
  • 2018-09-26
  • 2020-09-26
  • 2014-12-16
  • 2023-03-16
相关资源
最近更新 更多