mod_rewrite 用于映射文件中的特定域
我有一堆域,我想转到一个域,但该域的各个部分。
# this is what I currently have
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*\.?foo\.com$ [NC]
RewriteRule ^.*$ ${domainmappings:www.foo.com} [L,R=301]
# rewrite map file
www.foo.com www.domain.com/domain/foo.com.php
www.bar.com www.domain.com/domain/bar.com.php
www.baz.com www.domain.com/other/baz.php.foo
问题是我不想让每个域都成为 RewriteCond 的一部分。我尝试过,
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule (.*) http://%1/$1 [R=301,L]
但这适用于每个域。我只希望映射文件中的域进行重定向,然后如果它与映射文件中的任何域都不匹配,则继续进行其他重写。
I have a bunch of domains that I want to go to one domain but various parts of that domain.
# this is what I currently have
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*\.?foo\.com$ [NC]
RewriteRule ^.*$ ${domainmappings:www.foo.com} [L,R=301]
# rewrite map file
www.foo.com www.domain.com/domain/foo.com.php
www.bar.com www.domain.com/domain/bar.com.php
www.baz.com www.domain.com/other/baz.php.foo
The problem is that I don't want to have to have each domain be part of the RewriteCond. I tried
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule (.*) http://%1/$1 [R=301,L]
but that will do it for EVERY domain. I only want the domains that are in the mappings file to redirect, and then continue on to other rewrites if it doesn't match any domains in the mappings file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很接近,因为我找出了大小写匹配,但无法找出 www 前缀。如果我使用下面的第一个,它无需 www.如果我使用第二个,它可以与 www.如果我同时使用 - 都不起作用。
有什么想法吗?
I'm close as I figured out the the case matching, but unable to figure out the www prefix. If I use the first one below, it works without www. If I use the second one, it works with the www. If I use BOTH - neither work.
Any ideas?
你走在正确的轨道上。您所要做的就是使用地图上的管道操作符,这样您就可以掌握所有情况。
如果主机不在列表中,则第二个条件将不匹配。您仍然需要处理 www 前缀和大小写匹配,但您已经明白了。
You are on the right track. What you have to do is use the pipe operator on the map so that you have a catch-all.
The second condition will not match if the host is not in the list. You still have to deal with the www prefix, and the case matching, but you get the idea.