How to mod-rewrite all requests to single file without causing an infinite loop

天涯浪子 提交于 2019-12-12 16:15:46

问题


How can I take all requests to www.myurl.com/{ANYTHING} and send them all to www.myurl.com/index.php

I am finding I can send everything with:

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

This works great, except I am redirected to www.myurl.com/home/username/public_html because of my cpanel/apache installation. So instead I changed my code to

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

But this causes the infinite loop again.


回答1:


Try:

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



回答2:


With Apache, use mod_rewrite:

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



回答3:


This effectively sends me to index.php without causing a loop.

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

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


来源:https://stackoverflow.com/questions/12735720/how-to-mod-rewrite-all-requests-to-single-file-without-causing-an-infinite-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!