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

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

问题描述

这似乎是一个非问题对许多人来说(读:我无法找到答案),但我想更新下的htaccess code,不仅从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.

推荐答案

我有同样的问题(麻烦从指向一个子目录上的附加域网址剥离'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]

例如:<一href="http://www.addondomain.com/projects/a/gallery/4/2">http://www.addondomain.com/projects/a/gallery/4/2 - > <一个href="http://addondomain.com/projects/a/gallery/4/2">http://addondomain.com/projects/a/gallery/4/2

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

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