如何使用 .htaccess 将单个网页从一个域重定向到另一个域

发布于 2024-09-18 13:10:49 字数 220 浏览 1 评论 0原文

如何让以下重定向生效?

olddomain.com/employee-scheduling-software.html

要重定向到

newdomain.us/employee-scheduling-software.html

我确实打开了 mod_rewrite,但我基本上是这个领域的新手

How do I get the following redirect to work?

olddomain.com/employee-scheduling-software.html

To redirect to

newdomain.us/employee-scheduling-software.html

I do have mod_rewrite on, but I'm basically a complete novice in this area

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

萌面超妹 2024-09-25 13:10:49
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^employee-scheduling-software.html$ http://newdomain.example.org/employee-scheduling-software.html
</IfModule>

您可以将规则更改为:

RewriteRule ^employee-scheduling-software.html$ http://newdomain.example.org/employee-scheduling-software.html [R=301]

它将向浏览器发送 301 Moved Permanently 标头,以便浏览器更新其书签和内容。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^employee-scheduling-software.html$ http://newdomain.example.org/employee-scheduling-software.html
</IfModule>

You can change the rule into:

RewriteRule ^employee-scheduling-software.html$ http://newdomain.example.org/employee-scheduling-software.html [R=301]

which will send a 301 Moved Permanently header to the browser, so it updates its bookmarks and stuff.

避讳 2024-09-25 13:10:49

您可以在 olddomain.com 上的 .htaccess 中使用此代码:

RewriteEngine on
RewriteRule ^employee-scheduling-software\.html$ http://newdomain.us/employee-scheduling-software.html [R,QSA]

由于 ^employee-scheduling-software\.html$ 是 PERL 正则表达式,因此您需要转义“.html”中的点" 带有反斜杠 (\.)。

这只会将 employee-scheduling-software.html 重定向到新域。如果要将所有文件重定向到新域,请使用:

RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.us/$1 [R,QSA]

You could use this code in .htaccess on olddomain.com:

RewriteEngine on
RewriteRule ^employee-scheduling-software\.html$ http://newdomain.us/employee-scheduling-software.html [R,QSA]

Since the ^employee-scheduling-software\.html$ is a PERL regex, you need to escape the dot in ".html" with a backslash (\.).

This will just redirect employee-scheduling-software.html to the new domain. If you want to redirect all files to the new domain, use:

RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.us/$1 [R,QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文