如果来自某个域,则重定向到 .html
我有两个指向同一目录的域,但我想在回家时将它们重定向(通过 htaccess
中的 mod_rewrite
)到某个特定的 .html。
喜欢:
if (domain == 'firstdomain')
redirect firstdomain.html
else if (domain == 'seconddomain')
redirect seconddomain.html
I have two domains that are pointing to the same directory, but I would like to redirect them (via mod_rewrite
in htaccess
) to some specific .html when hitting home.
Like:
if (domain == 'firstdomain')
redirect firstdomain.html
else if (domain == 'seconddomain')
redirect seconddomain.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像 PHP 这样的语言更适合重定向单个页面。
以下代码会将
http://example.com/
重定向到http://example.com/example.html
和http://example.org /
到http://example.org/anotherpage.html
。http://www.example.com
将不受影响(请注意www.
部分)第一行将 HTTP 主机字段(也称为“域”)与
example.com
不区分大小写(^
标记字符串的开头,$
标记结尾)。如果匹配,页面将被重定向(第二行,
[R]
)到example.html
第三行和第四行的故事相同。
A language like PHP is better suited for redirecting a single page.
The following code will redirect
http://example.com/
tohttp://example.com/example.html
andhttp://example.org/
tohttp://example.org/anotherpage.html
.http://www.example.com
will be unaffected (note thewww.
part)The first line matches the HTTP Host field (a.k.a. 'domain') against
example.com
case-insensitive (^
marks the beginning of the string,$
marks the end).If there is a match, the page will be redirected (second line,
[R]
) toexample.html
The same story for the third and fourth lines.