问题
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