htaccess的重定向+隐藏子文件夹的网址 [英] htaccess redirect + hide subfolder in url
问题描述
我环顾四周,并试图有些事,有些工作,有些我以前不工作,或将捕获过多造成其他tomains也重定向。这对我的作品:
I've looked around and tried some things, some worked, some did't work or would capture too much causing other tomains to also redirect. This works for me:
# Redirect (also catches www.)
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ subfolder [L]
造成,如果你访问www.domain.com或domain.com
被重定向到domain.com/subfolder~~V
伟大的,但I'dd也喜欢/子部分从URL中隐藏。
resulting in if you visit www.domain.com OR domain.com being redirected to domain.com/subfolder Great, but I'dd also like the /subfolder part to be hidden from the url.
我如何实现这一目标?
How do I achieve this ?
请注意,我有多个域,每个域应该重定向到自己的文件夹。
我也希望每个页面仍然是在其各自的文件夹中看到。
Note that I have multiple domains, each should redirect to its own folder. I also want each page to still be visible in its respective folder.
所以www.domain.com/abc应该重定向到domain.com/subfolder/abc~~V,但显示domain.com/abc
So www.domain.com/abc should redirect to domain.com/subfolder/abc but show domain.com/abc
推荐答案
试试这个规则:
# remove www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule !^subfolder/ /subfolder%{REQUEST_URI} [L]
这篇关于htaccess的重定向+隐藏子文件夹的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!