我遇到了问题htaccess
,我想编写一个条件,阻止提供指定的文件.
如果请求的文件名存在,只需提供它,所以我有这个:
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
Run Code Online (Sandbox Code Playgroud)
但我怎么能得到一个指定的文件不会被提供?我有这条路径用于我的控制器动作.所以例如example/do_something.php
是文件的路径,do_something.php
但也是我的控制器操作的路径,我希望我的htaccess
文件服务此操作而不是此文件,但只有这个.
RewriteRule ^do_something\.php$ - [L,NC]
Run Code Online (Sandbox Code Playgroud)
它对我不起作用,但我设法通过将此文件重定向到我的前端控制器来解决它:
RewriteRule ^example/(.+)\.php$ %{ENV:BASE}/app.php [L]
Run Code Online (Sandbox Code Playgroud)
因此,在这种情况下,如果有人输入路径,example/do_something.php
则不会提供文件,并且请求将由前端控制器发送
完整示例:
# 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]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
271 次 |
最近记录: |