无形的mod_rewrite并不总是看不见!? (QUOT; WWW"和"没有子") [英] invisible mod_rewrite is not always invisible!? ("www" and "without subdomain")
问题描述
我的网站是使用的cPanel 11的主机上。
My site is on a host using cPanel 11.
不幸的是它重定向既www.e-motiv.net和e-motiv.net到public_html。
我想RESP。的public_html / www和的public_html /这无形给最终用户。
Unfortunatly it redirects both "www.e-motiv.net" and "e-motiv.net" to public_html. I want resp. public_html/www and public_html/ and this invisible to the end user.
我觉得最好的办法就是通过mod_rewrite的,所以我做了以下。
I thought the best way was through mod_rewrite, so I did the following.
文件空间看起来像这样(从的public_html /):
File space looks like this (from public_html/):
- /的.htaccess
- 的index.php
- /www/index.html
- /www/test/index.html
和我想这(第二部分看不见的!):
And I want this (second part invisible!):
- e-motiv.net - >的index.php
- www.e-motiv.net - > /www/index.php
- www.e-motiv.net/test - > /www/test/index.php
我认为这将做到这一点:
I thought this would do it:
RewriteCond %{HTTP_HOST} ^www.e-motiv.net$
RewriteCond %{REQUEST_URI} !/www
RewriteRule ^(.*)$ /www/$1 [NC,L]
1和2的工作,但是尽管3给出了正确的文件,它改变了地址!? (因此不可见)
所以,在地址栏你会得到:www.e-motiv.net/test - > www.e-motiv.net/www/test/
咦??
1 and 2 work, but although 3 gives the right file, it changes the address!? (so not invisible) So, in address bar you get: www.e-motiv.net/test -> www.e-motiv.net/www/test/ Huh??
如果mod_rewrite的是不是最好的解决办法,请快快!
If mod_rewrite is not the best solution, please do tell!
推荐答案
这是因为mod_dir的。 mod_dir增加了拖尾削减到映射到目录的URL。 mod_dir不知道用mod_rewrite的创建这些虚拟URL的。
This is because of mod_dir. mod_dir adds the tailing slashed to urls that map to directories. mod_dir is not aware of these 'virtual urls' created with mod_rewrite.
所以,无论是使用禁用此行为
So either disable this behavior by using
DirectorySlash Off
然而,这将使得请求中没有发现404 www.example.com/folder~~V结果。你可以用一些重写规则,虽然解决这个问题。因此,完整的解决方案会是这样的:
This will however make requests to www.example.com/folder result in a 404 not found. You can fix this with some rewriterule though. So the complete solution would be something like:
DirectorySlash Off
#www dir only
RewriteCond %{DOCUMENT_ROOT}/$0 -d
RewriteRule ^www/(.+[^/])$ /$1/ [R,L]
#other dirs
RewriteCond %{DOCUMENT_ROOT}/$0 -d
RewriteRule ^(.+[^/])$ /$1/ [R,L]
这篇关于无形的mod_rewrite并不总是看不见!? (QUOT; WWW"和"没有子")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!