我的 Laravel 项目中有一个 server.php 文件。在我的计算机中,我可以命令 PHP -S localhost:8000 server.php 所以如果我向 localhost:8000 发出 HTTP 请求,它会读取 server.php 文件。或者如果我输入这个 URL:localhost:8000/anything/anything it去读取 server.php 文件。但在我的 Linux 服务器中
如果我键入 domain/anything/anything 它会转到 var/www/anything/anything 并在那里阅读 index.php。但我只想读取 server.php 并将这些任何/任何内容传递给 server.php 文件,并且不将它们视为目录。执行此工作的 apache 配置是什么?
最佳答案
您可以使用 htaccess 重写规则
RewriteRule ^anything/anything$ /server.php [L]
我想在你的情况下你不希望它匹配确切的字符串(任何东西/任何东西)所以这可能是你正在寻找的解决方案:RewriteRule ^(.*)$ /server.php?path=$1 [L]
因此,上面的规则将检查在 url 之后输入的所有内容并将其作为 GET(路径变量)传递给 server.php
关于linux - 让 apache 只读取一个 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62533180/