问题描述
我的PHP项目在.htaccess中列出了十二个URL重写规则.
My PHP project has a dozen URL rewriting rules listed in .htaccess.
现在,我想以.phar
文件的形式提供应用程序,因此需要重新实现重写规则-可以作为第4个参数传递给Phar::webPhar()
的rewrite
函数.
Now I want to provide the application as a .phar
file and thus need to re-implement the rewrite rules the rewrite
function that can be passed to Phar::webPhar()
as 4th parameter.
有没有一种方法可以在我的PHP代码中重复使用.htaccess
重写规则,而无需直接在PHP中实现它们?只是解释"它们的某些库/扩展名/代码?
Is there a way to re-use the .htaccess
rewrite rules in my php code without implementing them in PHP directly? Some library/extension/code that just "interprets" them?
推荐答案
在打包.phar
文件之前,我使用.htaccess文件生成了一个正则表达式模式的PHP数组. github.com/cweiske/phorkie/blob/master/scripts/build-rewritemap.php"rel =" nofollow> build-rewritemap.php .
Before packaging up the .phar
file, I generate a PHP array of regex pattern from the .htaccess
file with build-rewritemap.php.
Phar::webPhar()
的重写处理程序然后遍历该数组并尝试匹配: https://github.com/cweiske/phorkie/blob /90f0bc1550eb0e5291f215552b22143fbe5e9398/src/stub-phar.php#L59
The rewrite handler of Phar::webPhar()
then iterates over that array and tries to match:https://github.com/cweiske/phorkie/blob/90f0bc1550eb0e5291f215552b22143fbe5e9398/src/stub-phar.php#L59
这篇关于Phar:重用.htaccess定义的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!