拒绝访问除index.php之外的所有文件但允许GET变量

时间:2012-11-09 20:38:40

标签: .htaccess rewrite

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

这是我当前的.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

1 个答案:

答案 0 :(得分:1)

以下规则会停止对index.php(带或不带)参数的直接请求:

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

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

相关问题