如何始终使用 mod_rewrite 从 url 中删除 WWW? [英] How to always remove WWW from a url with mod_rewrite?

查看:15
本文介绍了如何始终使用 mod_rewrite 从 url 中删除 WWW?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下方法尝试从 url 中删除 WWW:

I'm using the following to try and remove WWW from the url:

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) http://example.com$1 [R=301]

但由于某种原因它不起作用.有什么建议吗?

But for some reason it doesn't work. Any suggestions?

推荐答案

尝试:

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

没有mod_rewrite:

<VirtualHost 10.0.0.1:80>
        ServerName www.example.com
        Redirect permanent / http://example.com/
</VirtualHost>

完成以下 URL 中的步骤即可使用虚拟主机:在 Apache 中设置虚拟主机.

Virtual hosts can be used by completing the steps in the following URL: Setting Up A Virtual Host in Apache.

这篇关于如何始终使用 mod_rewrite 从 url 中删除 WWW?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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