首页 > 解决方案 > How to rewrite the rule in .htaccess to specific url

问题描述

Normally when load the URL http://www.example.com/ it goes to http://www.example.com/index.php.

I have to rewrite the url http://www.example.com/something into http://www.example.com/index.php/something

RewriteEngine on

RewriteRule ^([a-z0-9\.]+) http://www.example.com/index.php/$1 [NC]

causes loop

标签: phpregexapache.htaccess

解决方案


发生该循环是因为您没有将目标排除在外,index因此Rewriterule您重定向到 index 然后一次又一次地重定向。

让它像这样:

RewriteEngine on
RewriteRule !^(index|$)  index.php%{REQUEST_URI} [L]

那是在内部将请求重定向/something/index.php/something,如果您需要在外部重定向它,请告诉我相应地进行更改。


推荐阅读