.htaccess htaccess和301重定向

.htaccess htaccess和301重定向,.htaccess,.htaccess,我想改变方向 http://old.clients.domain.com 到 在htaccess文件中,我编写了一个永久重定向 Redirect 301 / http://clients.domain.com 当我键入old.clients.domain.com时,它会在地址栏中将地址更改为clients.domain.com,但它不会显示页面,而是在Firefox中显示: The page isn't redirecting properly Firefox has detected t

我想改变方向

http://old.clients.domain.com

在htaccess文件中,我编写了一个永久重定向

Redirect 301 / http://clients.domain.com
当我键入old.clients.domain.com时,它会在地址栏中将地址更改为clients.domain.com,但它不会显示页面,而是在Firefox中显示:

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

我做错了什么?谢谢。

我想它也会返回301


您必须将.htaccess文件仅放在

的目录中,我认为它也会返回301


如果它们指向同一根目录,则必须仅为

的目录放置.htaccess文件,最简单的方法是在根.htaccess文件中使用条件重写语句:

RewriteEngine On
RewriteBase   /

Rewritecond   %{HTTP_HOST} =old.clients.domain.com
RewriteRule   ^.*$         http://clients.domain.com/$0   [R=301,L]

您需要保护以防止重新重定向有效的
clients.domain.com
请求,而大多数浏览器(如Ff)会将这些请求视为无限重定向。

如果它们指向同一根目录,则最简单的方法是在root.htaccess文件中使用条件重写语句:

RewriteEngine On
RewriteBase   /

Rewritecond   %{HTTP_HOST} =old.clients.domain.com
RewriteRule   ^.*$         http://clients.domain.com/$0   [R=301,L]

您需要保护以防止重新重定向有效的
clients.domain.com
请求,而大多数浏览器(如Ff)会将这些请求视为无限重定向。

这是什么?难怪任何使用此示例的人都会遇到内部服务器错误=old.clients.domain.com无效

而不是

Rewritecond %{HTTP_HOST} =old.clients.domain.com
使用

因此,正确代码的示例如下

RewriteEngine On
RewriteBase /

Rewritecond %{HTTP_HOST} (www\.)?old.clients.domain\.com
RewriteRule ^.*$ http://new.clients.domain.com/$0 [R=301,L]

这将在将根域重定向到附加域时起作用,并防止出现错误,如“Firefox检测到服务器正在以一种永远无法完成的方式重定向对此地址的请求”

这是什么?难怪任何使用此示例的人都会遇到内部服务器错误=old.clients.domain.com无效

而不是

Rewritecond %{HTTP_HOST} =old.clients.domain.com
使用

因此,正确代码的示例如下

RewriteEngine On
RewriteBase /

Rewritecond %{HTTP_HOST} (www\.)?old.clients.domain\.com
RewriteRule ^.*$ http://new.clients.domain.com/$0 [R=301,L]

这将在将根域重定向到加载域时起作用,并防止出现“Firefox检测到服务器正在以一种永远无法完成的方式重定向对此地址的请求”之类的错误

它给出了此错误
内部服务器错误服务器遇到内部错误或配置错误,无法完成您的请求。
添加
序言和
尾部。如果ISE消失,则无法加载mod_rewrite或您输入了一个错误。它会导致此错误
内部服务器错误服务器遇到内部错误或配置错误,无法完成您的请求。
添加
序言和
尾部。如果ISE消失,则无法加载mod_rewrite,或者您输入了一个拼写错误。