.htaccess 从 URL + 目录中删除 WWW [英] .htaccess Remove WWW from URL + Directories

查看:26
本文介绍了.htaccess 从 URL + 目录中删除 WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对很多人来说似乎不是问题(阅读:我找不到答案),但我想更新以下 htaccess 代码,不仅从 URL 中删除www",而且访问的任何子目录.

This seems to be a non-issue for many people (read: I can't find an answer), but I would like to update the following htaccess code to not only remove the 'www' from the URL, but also any sub-directories that are accessed.

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

有了这个,http://www.example.com/any/ 解析得很好,但我希望它重定向http://example.com/any/ 与根一样.

With this, http://www.example.com/any/ resolves fine, but I want it to redirect to http://example.com/any/ as with the root.

推荐答案

我遇到了同样的问题(无法从指向附加域子目录的 URL 中删除www"),但经过一些试验和错误,这似乎对我有用:

I had the same problem (trouble stripping 'www' from URLs that point to a sub-directory on an add-on domain), but after some trial and error, this seems to work for me:

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

这篇关于.htaccess 从 URL + 目录中删除 WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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