简体   繁体   English

htaccess-如何强制使用http和非www

[英]htaccess - How to force http and non-www

I need to set a htaccess domain configuration where https redirects to http and all www requests to non-www. 我需要设置htaccess域配置,其中https重定向到http,所有www请求都重定向到非www。 I thought I could solve it with the following code but it does not work correctly. 我以为可以用以下代码解决它,但不能正常工作。 It only redirects http://www.example.com to http://example.com . 它仅将http://www.example.com重定向到http://example.com https requests end up at eg https://example.com with the hint that the connection is insecure. https请求以例如https://example.com结尾,提示连接不安全。

<IfModule mod_rewrite.c>

RewriteEngine On 
RewriteBase /

# Redirect HTTPS to HTTP
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Force non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]

</IfModule>

Most likely, your shared host proxies all HTTP connections to your site, and forwards them over HTTPS. 您的共享主机很可能将所有HTTP连接代理到您的站点,并通过HTTPS转发它们。 You never see the connection from the client, only the connection from your shared host proxy. 您永远不会看到来自客户端的连接,只会看到来自共享主机代理的连接。 Ask the shared host whether she does or will signal the information you need in HTTP headers such as Forwarded-SSL (or X-Forwarded-SSL). 询问共享主机是否在或将在HTTP标头(例如Forwarded-SSL(或X-Forwarded-SSL))中发出您需要的信息信号。

This worked for me. 这对我有用。

RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://example.com:80/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://example.com:80/$1 

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

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