重写 .domain.com/到 /subdomains//
我被我的 mod_rewrite 困住了(大约 4 个小时,是的,我也在 google 上搜索过)。 基本上我想创建动态子域。所以我只需创建一个新文件夹,它就会自动拥有自己的子域。让我给你举个例子:
/ (root)
/logs
/configs
/otherPrivateStuff
[...]
/subdomains (This is, where things get interesting)
/www (should be: www.domain.com) [domain.com is automatically 301 to www]
/aproject (should be: aproject.domain.com)
/anotherproject (should be: anotherproject.domain.com)
我的 .htaccess 看起来像这样:
# Mod Rewrite
RewriteEngine on
# Subdomains
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com(:[0-9]+)? [NC]
RewriteRule ^(.*) subdomains/%1/$1/ [NS,L]
http://project.domain .com/path/subpath/file.txt --> http://domain.com/subdomains/project/path/subpath/file.txt
这就像一个魅力,但有一个问题:如果网址如下所示,则此规则不适用: http://project.domain.com/subdomains/ 这就像根本没有重写一样。
我不明白这一点。这里有人可以帮助我吗? :)
I've got stuck with my mod_rewrite (for about 4 hours, yes, I googled, too).
Basically I want to create dynamic subdomains. So I just create a new folder and it automatically has it's own subdomain. Let me give you an example:
/ (root)
/logs
/configs
/otherPrivateStuff
[...]
/subdomains (This is, where things get interesting)
/www (should be: www.domain.com) [domain.com is automatically 301 to www]
/aproject (should be: aproject.domain.com)
/anotherproject (should be: anotherproject.domain.com)
My .htaccess looks like this:
# Mod Rewrite
RewriteEngine on
# Subdomains
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com(:[0-9]+)? [NC]
RewriteRule ^(.*) subdomains/%1/$1/ [NS,L]
http://project.domain.com/path/subpath/file.txt --> http://domain.com/subdomains/project/path/subpath/file.txt
This works like a charm, but there is a problem: this rule does not apply, if the url looks like this: http://project.domain.com/subdomains/ This beahaves like there's no rewriting at all.
I do not understand this. Can anybody out here help me? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定您想专门排除“子域”目录。为此,您只需使用:
我希望这对您来说正确。
I'm pretty sure you want to specifically exclude the "subdomains" directory. To do this, you can simply use:
I hope that worked correctly for you.