简明现代魔法 -> PHP服务器脚本 -> 使用.htaccess进行URL重写
使用.htaccess进行URL重写
2009-10-20
有些时候,我们不想让用户知道他访问我们站点具体的网页文件名字,出于安全性考虑,我们也有必要将具体的网页文件名隐藏掉。使用.htaccess进行URL重写可以达到这个目的。
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
#Replace url_handler.php for your filename
#that will handle the redirections.
RewriteCond %{REQUEST_FILENAME} !-s
Rewriterule (.*) url_handler.php
</IfModule>
将url_handler.php修改为index.php。假如网站有一个名叫nowamagic的文件夹,下面有一个index.php的文件,建立以上htaccess文件之后,用户只需输入xx/nowamagic/,即可访问该文件夹下的index.php文件。

