gpt4 book ai didi

php - 如何为不同于指定的 request_filename 编写重写条件

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:49:59 29 4
gpt4 key购买 nike

我遇到了 htaccess 的问题,我想编写一个条件来阻止提供指定文件。

如果请求的文件名存在,只需提供它,这样我就有了:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

但是我怎样才能做到不提供一个指定的文件呢?我有这条路径用于我的 Controller 操作。所以例如 example/do_something.php是文件 do_something.php 的路径,但也是我的 Controller 操作的路径,我希望我的 htaccess 文件服务于此操作而不是此文件,但仅此。

最佳答案

我试过 anubhava在他的answer中说

RewriteRule ^do_something\.php$ - [L,NC]

它对我不起作用,但我设法通过将这些文件重定向到我的前端 Controller 来解决它:

RewriteRule ^example/(.+)\.php$ %{ENV:BASE}/app.php [L]

所以在这种情况下,如果有人输入路径 example/do_something.php,文件将不会被提供并且请求由前端 Controller 发送

完整示例:

# If the requested filename exists
# And my route path for controller action is the same
# Don't serve file serve action
RewriteRule ^example/(.+)\.php$ %{ENV:BASE}/app.php [L]

# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]

关于php - 如何为不同于指定的 request_filename 编写重写条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29513358/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com