如何在不引起无限循环的情况下将所有请求重新编码为单个文件

时间:2012-10-04 20:51:49

标签: apache mod-rewrite cpanel whm

如何将所有请求发送至www.myurl.com/{ANYTHING}并将其全部发送至www.myurl.com/index.php

我发现我可以发送所有内容:

RewriteRule .* index.php [R=Permanent,L]

这很好用,但由于我的cpanel / apache安装,我被重定向到www.myurl.com/home/username/public_html。所以我将代码更改为

RewriteBase /
RewriteRule .* index.php [R=Permanent,L]

但是这会再次导致无限循环。

3 个答案:

答案 0 :(得分:2)

尝试:

RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule .* /index.php [R=Permanent,L]

答案 1 :(得分:0)

使用Apache,使用mod_rewrite:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]

答案 2 :(得分:-1)

这有效地将我发送到index.php而不会导致循环。

RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteRule ^(.*)$ - [L]

RewriteRule ^(.*)$ /index.php?url=%{REQUEST_URI} [R=302,L,QSA]