tags:

views:

39

answers:

4

domain.com/index/ to domain.com/index.php

domain.com/index/hello to domain.com/index.php/hello

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

A: 

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.

Andrei Serdeliuc
I change to: RewriteRule ^([^/.]+)((/[^/]+)*)/?$ $1.php$2 [L] <br />http://domain.com/index/ to http://domain.com/index.php works fine<br />http://domain.com/index/hello to http://domain.com/index.php/hello not work
ni
A: 

Clearly your regex need escape for /. Try this instead:

RewriteRule ^([^\/]+)\/(.*)$      $1.php/$2   [L]
Donny Kurnia
Thanks,but it not works
ni
A: 
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.

ni
Try to check the apache's `access_log`. You can find the `.htaccess` translation result there. The error usually because apache didn't pass the `PATH_INFO` to php.
Donny Kurnia
A: 

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 …

Gumbo
I did add RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME}.php -f
ni
@ni: That’s probably the problem: `%{REQUEST_FILENAME}.php -f` fails and so nothing gets rewritten. Just try my rule.
Gumbo