网站安全问题::网址重写

时间:2013-08-12 13:35:28

标签: apache security .htaccess url

我想知道无论如何我可以在.htaccess中重写我的网址。由于查询字符串的使用,我的网站被黑客攻击。我当前的网站网址结构如下:

www.mysite.com/index.php?page=about.php
www.mysite.com/index.php?page=services.php
www.mysite.com/index.php?page=home.php

如何在.htaccess文件中替换我的“index.php?page =”,以便访问者只能访问以下页面:“www.mysite.com/service.php”,“www.mysite.com/ about.php“etc

如果你能在这方面帮助我,我将不胜感激。

1 个答案:

答案 0 :(得分:1)

一揽子解决方案是进行通配符匹配,但这只是重写并且不能解决安全问题。

RewriteEngine On
RewriteRule ^index.php?page=(.*)$ /$1.php [NC]

要把事情锁定一点,你可以在你的重写中具体说明:

RewriteEngine On
RewriteRule ^index.php?page=about.php$ /about.php [NC]
RewriteRule ^index.php?page=services.php$ /services.php [NC]
RewriteRule ^index.php?page=home.php$ /home.php [NC]

此方法需要更多的手动干预,但如果您没有很多页面,这可能是一个可行的权衡。如果您需要重写的页面数是手动无法管理的,那么您需要在PHP脚本中使用逻辑补充这一点。

关于如何使用Apache重写规则的完整纲要,我建议您阅读official documentation

相关问题