Apache mod_rewrite rules problems
domain.com/index/ to domain.com/index.php
domain.com/index/hello to domain.com/index.php/hello
开发者_JAVA百科The site is use path_info,and the default rule not works:
RewriteRule ^([^/]+)/(.*)$ $1.php/$2 [L]
I change to: RewriteRule ^([^/.]+)((/[^/]+)*)/?$ $1.php$2 [L]
That was strange
domain.com/index/ to domain.com/index.php works fine
domain.com/index/hello to domain.com/index.php/hello not work
and it says No input file specified.
Php is run in fast cgi mode in apache
I believe it should be:
RewriteRule ^([^/]+)/(.*)?$ $1.php/$2 [L]
So the 2nd group is optional.
Also, I would advise you not to use variable passed in the url to match files, it could lead to security issues.
Clearly your regex need escape for /
. Try this instead:
RewriteRule ^([^\/]+)\/(.*)$ $1.php/$2 [L]
I change to: RewriteRule ^([^/.]+)((/[^/]+)*)/?$ $1.php$2 [L]
That was strange
domain.com/index/ to domain.com/index.php works fine
domain.com/index/hello to domain.com/index.php/hello not work
and it says No input file specified.
You need to exclude matches that end with .php
:
RewriteCond $1 !.+\.php$
RewriteRule ^([^/]+)/(.*)$ $1.php/$2 [L]
Otherwise /index.php/hello
would also be rewritten to /index.php.php/hello
and that would be rewritten to /index.php.php.php/hello
and that …
精彩评论