拒绝访问所有文件,但index.php,但允许获取变量



基本上,我不希望访问我的网站的人获取所有文件,但是我在互联网上尝试并发现的所有内容都不允许使用index.php之后的获取变量的用法。我正在使用重写来制作domain.com/lol to Index.php?笑。

这是我当前的.htaccess文件,如果您想修改它以使我更容易,请继续。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule .? http://domain.com%{REQUEST_URI} [L,R=301]
RewriteRule ^act/(.*)$ index.php?act=$1
RewriteRule ^code/(.*)$ index.php?code=$1
RewriteRule ^login$ index.php?login
RewriteRule ^logout$ index.php?logout
RewriteRule ^add$ index.php?add
RewriteRule ^tac$ index.php?tac
RewriteRule ^profile$ index.php?profile

以下规则停止直接请求到index.php(有或没有)参数:

# block direct requests to index.php and redirect it to /
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index.php$ /

如果需要,您可以根据允许的允许和不确切的条件来更改重写目标和/或添加更多条件。

最新更新