如何使用 .htaccess 将单个网页从一个域重定向到另一个域
如何让以下重定向生效?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将规则更改为:
它将向浏览器发送
301 Moved Permanently
标头,以便浏览器更新其书签和内容。You can change the rule into:
which will send a
301 Moved Permanently
header to the browser, so it updates its bookmarks and stuff.您可以在 olddomain.com 上的 .htaccess 中使用此代码:
由于
^employee-scheduling-software\.html$
是 PERL 正则表达式,因此您需要转义“.html”中的点" 带有反斜杠 (\.
)。这只会将
employee-scheduling-software.html
重定向到新域。如果要将所有文件重定向到新域,请使用:You could use this code in .htaccess on olddomain.com:
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: