2

我想将所有用户页面请求重定向到同一域上的页面。

例如,我有一个“正在建设中,BRB”页面,我希望所有用户在尝试访问站点上的任何页面时都能看到该页面。

我尝试使用这个:

Redirect 302 / http://www.domain.com/index2.php

这样做的目的是尝试将重定向也应用到 index2.php 页面,但它会卡在一个循环中,然后用户会看到这个循环,直到浏览器停止。

http://www.domain.com/index2.phpindex2.phpindex2.phpindex2.php etc., etc,

关于如何将该规则写入除该页面之外的任何想法?

4

4 回答 4

2

您必须排除要重定向到的文件。这是 mod_rewrite 的示例:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule !^index2\.php$ /index2.php [L,R=302]
</IfModule>
于 2009-04-13T15:41:15.320 回答
1

为了防止无限循环(index2.php <--> index2.php):

仅重定向如果要重定向的 URL 不包含字符串 'index2.php'

RewriteCond %{QUERY_STRING} !index2.php
RewriteRule ^(.*)$ /index2.php [L,R=301]
于 2012-08-26T01:37:49.323 回答
0

你可以使用 mod_rewrite

<IfModule mod_rewrite.c>
RewriteCond {REQUEST_URI} !=/index2.php
RewriteEngine on
RewriteRule ^.*$ /index2.php
# End .HTACCESS
</IfModule>

于 2009-04-13T14:58:43.333 回答
0

我会更倾向于使用略有不同的

Options +FollowSymLinks 
<IfModule mod_rewrite.c>
    RewriteEngine on 
    RewriteRule ^/.*$ /index2.php [R=307,L]
</IfModule>

这将使您返回重定向的临时移动状态。

省略这组标志意味着 mod_rewrite 默认会返回 302 Found 状态。

高温高压

干杯,

于 2009-04-13T15:37:17.623 回答