Mod rewrite Apache mod_重写规则问题
domain.com/index/ 到 domain.com/index.php domain.com/index/hello 到 domain.com/index.php/hello 该站点为“使用路径\信息”,默认规则不起作用:Mod rewrite Apache mod_重写规则问题,mod-rewrite,Mod Rewrite,domain.com/index/ 到 domain.com/index.php domain.com/index/hello 到 domain.com/index.php/hello 该站点为“使用路径\信息”,默认规则不起作用: RewriteRule ^([^/]+)/(.*)$ $1.php/$2 [L] 我改为:RewriteRule^([^/]+)((/[^/]+)*)/?$$1.php$2[L] 真奇怪 domain.com/index/到domain.com/in
RewriteRule ^([^/]+)/(.*)$ $1.php/$2 [L]
我改为:RewriteRule^([^/]+)((/[^/]+)*)/?$$1.php$2[L]
真奇怪
domain.com/index/到domain.com/index.php效果良好
domain.com/index/hello to domain.com/index.php/hello不工作
并且它说没有指定输入文件。
Php在apache中以快速cgi模式运行我认为应该是:
RewriteRule ^([^/]+)/(.*)?$ $1.php/$2 [L]
所以第二组是可选的
另外,我建议您不要使用url中传递的变量来匹配文件,这可能会导致安全问题。很明显,您的正则表达式需要escape for
/
。请尝试以下方法:
RewriteRule ^([^\/]+)\/(.*)$ $1.php/$2 [L]
真奇怪
domain.com/index/到domain.com/index.php工作正常
domain.com/index/hello to domain.com/index.php/hello不工作
它表示未指定输入文件。您需要排除以
结尾的匹配项。php
:
RewriteCond $1 !.+\.php$
RewriteRule ^([^/]+)/(.*)$ $1.php/$2 [L]
否则,
/index.php/hello
也将被重写为/index.php.php/hello
,这将被重写为/index.php.php.php/hello
,并且…我更改为:RewriteRule^([^/]+)((/[^/]+)*)/?$$1.php$2[L]工作正常
不工作我确实添加了第二个%{请求文件名}-重写cond%{REQUEST_FILENAME}.php-f@ni:这可能就是问题所在:
%{REQUEST_FILENAME}.php-f
失败,因此不会重写任何内容。试试我的规则。试着检查apache的access\u log
。您可以在那里找到.htaccess
翻译结果。该错误通常是因为apache没有将路径\u INFO
传递给php。
RewriteCond $1 !.+\.php$
RewriteRule ^([^/]+)/(.*)$ $1.php/$2 [L]