如果来自某个域,则重定向到 .html

发布于 2024-09-29 19:03:13 字数 255 浏览 2 评论 0原文

我有两个指向同一目录的域,但我想在回家时将它们重定向(通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˉ厌 2024-10-06 19:03:13

[..] 我想在回到家时将它们重定向到一些特定的 .html 。

像 PHP 这样的语言更适合重定向单个页面。

以下代码会将 http://example.com/ 重定向到 http://example.com/example.htmlhttp://example.org /http://example.org/anotherpage.htmlhttp://www.example.com 将不受影响(请注意 www. 部分)

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^$ example.html [R]
RewriteCond %{HTTP_HOST} ^example.org$ [NC]
RewriteRule ^$ anotherpage.html [R]

第一行将 HTTP 主机字段(也称为“域”)与 example.com 不区分大小写(^ 标记字符串的开头,$ 标记结尾)。
如果匹配,页面将被重定向(第二行,[R])到 example.html
第三行和第四行的故事相同。

[..] I would like to redirect them to some specific .html when hitting home.

A language like PHP is better suited for redirecting a single page.

The following code will redirect http://example.com/ to http://example.com/example.html and http://example.org/ to http://example.org/anotherpage.html. http://www.example.com will be unaffected (note the www. part)

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^$ example.html [R]
RewriteCond %{HTTP_HOST} ^example.org$ [NC]
RewriteRule ^$ anotherpage.html [R]

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]) to example.html
The same story for the third and fourth lines.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文