gpt4 book ai didi

.htaccess - 更改站点域

转载 作者:行者123 更新时间:2023-12-02 11:28:36 25 4
gpt4 key购买 nike

快速 htaccess 问题

我正在更改与站点关联的域,并想知道是否可以设置 htaccess 来进行以下类型的重定向:

重定向 http://www.oldomain.com/contact-us

http://www.newdomain.com/contact-us

基本上是一个全局重定向,重定向到新域,但保留用户输入的 URL 的其余部分。

更新:我最终使用了以下代码,它完美地工作了

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]

最佳答案

当然,您可以轻松地做到这一点,而不必弄乱神秘的 RewriteEngine 命令。 (RewriteEngine 有其用武之地,但对于像这样简单的事情来说肯定不需要它。)

Redirect permanent / http://newdomain.com/

重定向指令会自动保留指示重定向的路径部分之后的所有内容。 documentation for the Redirect directive用一个例子解释这一点:

Example:

Redirect /service http://foo2.bar.com/service

如果客户端请求http://myserver/service/foo.txt ,它会被告知访问 http://foo2.bar.com/service/foo.txt相反。

关于.htaccess - 更改站点域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4704195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com