【问题标题】:make apache to read just one php file让 apache 只读取一个 php 文件
【发布时间】:2020-10-13 10:07:06
【问题描述】:

我的 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 配置是什么?

【问题讨论】:

    标签: linux laravel apache dns centos


    【解决方案1】:

    你可以使用htaccess重写规则

    RewriteRule ^anything/anything$ /server.php [L] 
    

    我想在你的情况下你不希望它匹配确切的字符串(任何东西/任何东西)所以这可能是你正在寻找的解决方案:

    RewriteRule ^(.*)$ /server.php?path=$1 [L]
    

    所以上面的规则会检查在 url 之后输入的所有内容,并将其作为 GET(路径变量)传递给 server.php

    【讨论】:

    • thanks.i read rewrite rule usage and write it in my htaccess file.it works.
    • @sina-sharifi 很高兴能帮上忙 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    • 2022-08-21
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 2020-01-25
    • 1970-01-01
    相关资源
    最近更新 更多