2010-01-14 111 views
0

domain.com/index/ 到 domain.com/index.phpApache的mod_rewrite的规则问题

domain.com/index/hello 到 domain.com/index.php/hello

该网站是使用PATH_INFO和默认规则不适用:

RewriteRule ^([^/]+)/(.*)$  $1.php/$2 [L] 

我更改为:RewriteRule ^([^/.]+)((/[^/]+)*)/?$ $1.php$2 [L]

这是奇怪

domain.com/index/到domain.com/index.php 工作正常

domain.com/index/hello到domain.com/index.php/hello 不工作

并且它说未指定输入文件。

PHP是运行在快速CGI模式阿帕奇

回答

0

我相信它应该是:

RewriteRule ^([^/]+)/(.*)?$  $1.php/$2 [L] 

所以,第二组是可选的。

此外,我会建议你不要使用URL中传递的变量来匹配文件,它可能会导致安全问题。

+0

我更改为:重写规则^( [^ /。] +)((/ [^ /] +)*)/?$ $ 1.php $ 2 [L]
http://domain.com/index/ to http://domain.com/ index.php正常工作
http://domain.com/index/hello to http://domain.com/index.php/hello not working – 2010-01-14 11:35:23

0

显然你的正则表达式需要逸出/。试试这个:

RewriteRule ^([^\/]+)\/(.*)$  $1.php/$2 [L] 
+0

谢谢,但它不起作用 – 2010-01-14 11:25:18

0
I change to: RewriteRule ^([^/.]+)((/[^/]+)*)/?$ $1.php$2 [L] 

这是奇怪

domain.com/index/到domain.com/index.php精细

作品domain.com/index/hello域.com/index.php/hello不工作

它说没有指定输入文件。

+0

尝试检查Apache的'access_log'。你可以在那里找到'.htaccess'的翻译结果。这个错误通常是因为apache没有将'PATH_INFO'传递给php。 – 2010-01-14 14:06:29

0

你需要排除与.php结束比赛:

RewriteCond $1 !.+\.php$ 
RewriteRule ^([^/]+)/(.*)$  $1.php/$2 [L] 

否则/index.php/hello也将被改写为/index.php.php/hello这将改写为/index.php.php.php/hello和...

+0

我确实添加了 RewriteCond%{REQUEST_FILENAME}!-d RewriteCond%{REQUEST_FILENAME} .php -f – 2010-01-14 11:55:52

+0

@ni:这可能是问题:'%{REQUEST_FILENAME} .php -f'失败,因此没有重写。试试我的规则。 – Gumbo 2010-01-14 11:57:37