[英]Apache RewriteRule for forbidding all URLs except one
I have a problem finding the right RewriteRules for my problem. 我在为我的问题找到正确的RewriteRules时遇到问题。
I want to configure a ruleset in a Apache vhost configuration. 我想在Apache vhost配置中配置一个规则集。
My goal is that all URLs end at a 403 Forbidden. 我的目标是所有URL都以“ 403禁止”结尾。 Only the /api call should go to the index.php, which is the entry-point for my symfony project. 只有/ api调用应该转到index.php,这是我的symfony项目的入口点。
Right now I have the following, but it does not work correctly: 现在,我有以下内容,但无法正常工作:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/api$
RewriteRule (.*) - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
With this rules, all calls end as 403. 使用此规则,所有呼叫均以403结尾。
The other way round it works: 相反,它起作用:
RewriteCond %{REQUEST_URI} !^/api$
This way, all URls arrive in my symfony project. 这样,所有URls都进入了我的symfony项目。 Except /api which ends at 403. But I dont want it this way. / api除了以403结尾。但是我不希望这样。 As mentioned I want it the other way round. 如前所述,我想反过来。
Thanks for your help! 谢谢你的帮助!
You're close. 你近了 Use the raw request to ensure people can't visit index.php
. 使用原始请求来确保人们无法访问index.php
。
RewriteCond %{THE_REQUEST} ^\S+\s+/api/?(?:\?\S*)?\s
RewriteRule ^ index.php [END]
RewriteRule ^ - [F]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.