Apache 使用.htaccess重定向

Apache 使用.htaccess重定向,apache,.htaccess,http-status-code-302,Apache,.htaccess,Http Status Code 302,我想将所有用户页面请求重定向到同一域上的页面 例如,我有一个“正在建设中,BRB”页面,我希望所有用户在尝试访问网站上的任何页面时都能看到该页面 我试着用这个: Redirect 302 / http://www.domain.com/index2.php 这样做的目的是尝试将重定向应用到index2.php页面,它会陷入一个循环中,用户会看到这个循环,直到浏览器停止 http://www.domain.com/index2.phpindex2.phpindex2.phpindex2.php

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

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

我试着用这个:

Redirect 302 / http://www.domain.com/index2.php
这样做的目的是尝试将重定向应用到index2.php页面,它会陷入一个循环中,用户会看到这个循环,直到浏览器停止

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

除了那个页面之外,你知道如何写那个规则吗?

你可以使用mod_rewrite



重写cond{REQUEST_URI}=/index2.php
重新启动发动机
重写规则^.*$/index2.php
#结束。HTACCESS


我更倾向于使用稍微不同的

Options +FollowSymLinks 
<IfModule mod_rewrite.c>
    RewriteEngine on 
    RewriteRule ^/.*$ /index2.php [R=307,L]
</IfModule>
Options+FollowSymLinks
重新启动发动机
重写规则^/*$/index2.php[R=307,L]
这将允许您为重定向返回“已暂时移动”状态

省略这组标志意味着mod_rewrite将在默认情况下返回302 Found状态


干杯,

您必须排除要重定向到的文件。下面是一个mod_rewrite的示例:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule !^index2\.php$ /index2.php [L,R=302]
</IfModule>

重新启动发动机
重写规则^index2\.php$/index2.php[L,R=302]
防止无止境循环(index2.php index2.php): 仅当要重定向的URL不包含字符串“index2.php”时才重定向

RewriteCond %{QUERY_STRING} !index2.php
RewriteRule ^(.*)$ /index2.php [L,R=301]

我可能做错了,但我的broswer在尝试此操作时返回了“太多重定向”错误。我如何编写此代码,使其不会重写正确显示页面所需的CSS文件?无需指定302返回,mod|U rewrite默认情况下会这样做。@Tom:添加RewriteCond指令以解释其他URI路径:RewriteCond%{REQUEST_URI}^/(css | images | foobar)/`。我想我们已经达到了目标,但当我添加该指令时,重定向停止工作。。。。RewriteCond%{REQUEST_URI}^/(_assets)/RewriteRule上的RewriteEngine^index2\.php$/index2.php[L,R=302]抱歉,忘记排除您要提供服务的文件。我已经更新了。谢谢Eddy,但我仍然收到一个内部服务器错误,你知道为什么吗?Hrm,你能添加一些日志吗?例如)重写loglevel 9/path/to/logsa一些图像,包括页眉和页脚信息,这可能是原因吗?意思是它试图重定向包含文件?哦,仅供参考,我已经尝试了上面的代码,现在它根本不做任何重定向。。。