不可见的 mod_rewrite 并不总是不可见的!? (“www”和“无子域”)
我的网站位于使用 cPanel 11 的主机上。
不幸的是,它将 “www.e-motiv.net”和“e-motiv.net” 重定向到 public_html。 我想要回复。 public_html/www 和 public_html/ 这对最终用户不可见。
我认为最好的方法是通过 mod_rewrite,所以我做了以下操作。
文件空间看起来像这样(来自 public_html/):
- /.htaccess
- /index.php
- /www/index.html
- /www/test/index.html
我想要这个(第二部分不可见!):
- e-motiv.net -> ; /index.php
- www.e-motiv.net -> /www/index.php
- www.e-motiv.net/test -> /www/test/index.php
我认为这可以做到:
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/ 啊??
如果 mod_rewrite 不是最好的解决方案,请告诉我们!
My site is on a host using cPanel 11.
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.
I thought the best way was through mod_rewrite, so I did the following.
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 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??
If mod_rewrite is not the best solution, please do tell!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为 mod_dir。 mod_dir 将尾部斜杠添加到映射到目录的 url 中。 mod_dir 不知道这些使用 mod_rewrite 创建的“虚拟 URL”。
因此,要么通过使用禁用此行为,
但是,这将向 www.example.com/folder 发出请求,导致找不到 404。不过,您可以通过一些重写规则来解决这个问题。所以完整的解决方案是这样的:
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
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: