使用Apache WWW以非WWW URL(删除WWW)(的.htaccess) [英] WWW to NON WWW Urls (Remove WWW) using Apache (.htaccess)

查看:591
本文介绍了使用Apache WWW以非WWW URL(删除WWW)(的.htaccess)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重定向我的网站从 https://www.website.com/ 到的 https://website.com/

SSL 正确安装在我的服务器上。

我使用的阿帕奇并要做到这一点使用的阿帕奇(或的httpd.conf / ssl.conf中的.htaccess

我几乎用所有我能搜索方法,但没有为我工作。

http://www.website.com/ 正确重定向到的 https://website.com/

http://website.com/ 正确重定向到的 https://website.com/

不过, https://www.website.com/ 不正确重定向到的 https://website.com/

它给了我无效证书错误,当我加入异常(接受证书)到浏览器然后将其重定向到 https://开头的网站.COM / 。但我不希望添加这个异常(添加浏览器证书)

请注意,我的SSL证书签发website.com,而不是www.website.com。

以下是我的.htaccess规则和条件

  RewriteEngine叙述上

的RewriteCond%{} HTTPS关闭
重写规则^ $ HTTPS(*):// {REQUEST_URI} [L,R = 301]

的RewriteCond%{HTTP_HOST} ^ WWW \。(。*)$ [NC]
重写规则^ $ HTTPS(*)://%1%{REQUEST_URI} [R = 301,QSA,NC,L]
 

我已经使用下列太多,但没有任何工作。

  RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST}!^ domain.com $ [NC]
重写规则^(。*)$ https://domain.com/$1 [L,R = 301]
 

用于这很好,但没有运气

  RewriteEngine叙述上
的RewriteCond%{HTTP_HOST}!^ your-site.com $ [NC]
重写规则^(。*)$ https://your-site.com/$1 [L,R = 301]
 

没有运气这一点

  RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^ WWW \。
重写规则^(。*)$ http://example.com/$1 [R = 301,L]
 

我已经试过5-6其他(类似于以上)的解决方案很好,但没有奏效。所有的工作2模式我上面提到的,但没有工作的 HTTPS:// WWW

注意的.htaccess这些条件都达到了,我的意思是的.htaccess没有被忽视,我已经使用重定向的验证,也上述2模式工作为好。

的httpd.conf / ssl.conf中文件的AllowOverride 设置为所有

我有机会获得的httpd.conf / ssl.conf中

PHP版本 5.5.29

阿帕奇 2.4.6(CentOS的)的OpenSSL / 1.0.1e-FIPS PHP / 5.5.29

主机名:端口 website.com:443

最后但并非最不重要的我的网站 https://website.com/ 不要在Internet Explorer和Safari浏览器和开放提供证明文件的问题(错误),但是当我检查使用SSL跳棋(多个),我的域名,然后所有的SSL跳棋提到SSL已正确安装。

检查这一形象,这将解释事情变得更好。

http://i.imgur.com/lOy65rs.jpg

完整的.htaccess下面给出


 选项+了FollowSymLinks
的DirectoryIndex index.html的Home.php的index.php

RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST} ^ WWW \。(。*)
重写规则^ * $ HTTPS://%1 / $ 1 [R = 301,L]

的RewriteCond%{} HTTPS关闭
重写规则^ $ HTTPS(*):// {REQUEST_URI} [L,R = 301]

重写规则^(博客)($ | /) -  [L]
(。*)?重写规则^ / $的index.php MOD = resturants和放大器; 1名= $&放大器;%{QUERY_STRING} [L]
重写规则^ $ Home.php [L]
< IfModule mod_rewrite.c>
的RewriteCond%{REQUEST_URI} /+[^\.]+$
重写规则^(。+ [^ /])$%{REQUEST_URI} / [R = 301,L]
< / IfModule>
 


请如果有人能帮助?

在此先感谢

解决方案
  

请注意,我的SSL证书签发website.com,而不是   www.website.com。

那是你的主要问题的。您现在的永远的将是能够从 WWW 重定向到非WWW 没有< STRONG>有效证书 WWW 。究其原因是Web服务器处理其他任何东西,包括任何重写规则之前,连接处理第一。所以,当你的浏览器中使用https协议连接到你的网站,它要检查是否有有效的证书,因为这是SSL的本质,以确保连接牢固。然后,一旦做到这一点,Apache会处理,你有一个地方可以改写Web服务器的规则。因此它不能从万维网重写到非万维网,直到连接正确完成。为了要做到这一点,你还需要一个证书 WWW 为好。重写规则是没有问题的。

这个话题出现相当频繁和有没有办法解决它。这就是SSL /加密的性质以及它是如何工作的。

在购买证书,尽量不买只是域名,因为部分的CA的只会给你加www。但是如果你使用 www.example.com 在您的CSR,您将同时获得 www.example.com example.com 在相同的证书99%的时间。然后,你就不必担心这个问题。他们是愚蠢便宜,所以它不应该是一个问题,让一个又一个。 SSls.com有他们为4.99 /年。

I have to redirect my website from https://www.website.com/ to https://website.com/.

SSL is properly installed on my server.

I am using Apache and have to do this using Apache (either httpd.conf/ssl.conf or .htaccess)

I have used almost all of the methods I could search but none works for me.

http://www.website.com/ redirects properly to https://website.com/

http://website.com/ redirects properly to https://website.com/

But https://www.website.com/ do not redirect properly to https://website.com/.

It gives me invalid certificate error and when I add exception (accept the certificate) to browser then it redirects to https://website.com/. But I don't want to add this exception (adding the certificate in browser)

Please note that my SSL certificate is issued for website.com and not www.website.com.

Following are my .htaccess rules and conditions

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]

I have used following too but didn't worked either

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ https://domain.com/$1 [L,R=301]

Used this as well but no luck

RewriteEngine On
RewriteCond %{HTTP_HOST} !^your-site.com$ [NC]
RewriteRule ^(.*)$ https://your-site.com/$1 [L,R=301]

No luck with this too

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

I have tried 5-6 other (similar to above) solutions as well but none worked. all work for 2 patterns I mentioned above but none works for the https://www.

Note that these conditions of .htaccess are reached, I mean .htaccess is not being ignored, I have verified using redirects and also above mentioned 2 patterns are working as well.

In httpd.conf/ssl.conf files the AllowOverride is set to All.

I am having access to httpd.conf/ssl.conf.

PHP Version 5.5.29

Apache 2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.5.29

Hostname:Port website.com:443

Last but not least my website https://website.com/ do not open in Internet Explorer and Safari and give certificate issues (errors) but when I check my domain using SSL checkers (multiple) then all SSL checkers mentions that SSL is properly installed.

Check this image, this will explain things better

http://i.imgur.com/lOy65rs.jpg

Complete .htaccess is given below


Options +FollowSymlinks 
DirectoryIndex index.html Home.php index.php

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://{REQUEST_URI} [L,R=301]

RewriteRule ^(blogs)($|/) - [L]
RewriteRule ^(.*)/$ index.php?mod=resturants&name=$1&%{QUERY_STRING} [L]
RewriteRule ^$ Home.php [L]
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
</IfModule>


Please if anyone can help?

Thanks in advance

解决方案

Please note that my SSL certificate is issued for website.com and not www.website.com.

That is your main problem. You are never going to be able to redirect from www to non www without a valid certificate for www. The reason is the connection is handled first before the web server processes anything else including any rewrite rules. So when your browser connects to your site using the https protocol, it has to check for a valid certificate because that's the very nature of SSL to make sure the connection is secure. Then once that is done, Apache will process web server rules that you have in place like rewrites. So it can't rewrite from www to non www until the connection is completed correctly. In order for that to happen you also need a certificate for www as well. The rewrite rules are not the problem.

This topic comes up quite frequently and there is no way around it. That's the nature of SSL/encryption and how it works.

When buying a cert, try not buying just the domain name, because some CA's will only give you that without www. But if you use www.example.com in your CSR you will get both www.example.com and example.com in the same certificate 99% of the time. Then you won't have to worry about this issue. They are stupid cheap so it shouldn't be an issue to get another one. SSls.com has them for 4.99/yr.

这篇关于使用Apache WWW以非WWW URL(删除WWW)(的.htaccess)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆