我在运行 XAMPP 的 win8 机器上。我有一个使用 .htaccess 文件设置的虚拟主机目录。我一直在研究如何重写 url,我发现了 RewriteEngine 模块。在我的 httpd.conf apache 文件中,该模块已启用:
LoadModule rewrite_module modules/mod_rewrite.so
似乎下一步是像这样更新我的 .htaccess 文件:
php_value register_globals off
DirectoryIndex default.php index.php
ErrorDocument 404 /filenotfound.html
RewriteEngine On
RewriteBase /
RewriteRule ^Home$ Default.php [L]
RewriteRule ^AboutMe$ About.php [L]
RewriteRule ^Work$ Work.php [L]
RewriteRule ^Blog//Categories$ Blog/Categories.php [L]
RewriteRule ^Blog//([^/.]+)/?$ Blog/Posts.php?val=$1 [L]
我已经关注了几个 SO 问题(配置和重写 w/params),但我什至无法让最简单的重写工作。我已经重新启动了 apache 几次,但没有任何结果。
当我在这里时,这是我的文件夹结构,归结为所有相关内容:
root
.htaccess
Blog
AuthorPanel.php
Categories.php
Post.php
Posts.php
Default.php
About.php
Work.php
这些是我希望实现的重写(我已经尝试了大部分):
site.com/Default.php => site.com/Home
site.com/About.php => site.com/AboutMe
site.com/Blog/Categories.php => site.com/Blog/Categories
site.com/Blog/Posts.php?id=3&val=Android => site.com/Blog/Android
site.com//Blog/Post.php?id=4&title=Working+with+ActionBar => site.com/Blog/Working-with-ActionBar
更新 1在 httpd-vhosts.conf 我什至尝试使用 RewriteEngine on 和 rewrite 规则,但也没有运气:
<VirtualHost *>
DocumentRoot "C:/Users/ben/Documents/PHP/benWIT"
ServerName benWIT.local
<Directory "C:/Users/ben/Documents/PHP/benWIT">
RewriteEngine on
Order allow,deny
AllowOverride all
Allow from all
Require all granted
RewriteRule ^Home$ Default.php [L]
RewriteRule ^AboutMe$ About.php [L]
RewriteRule ^Work$ Work.php [L]
</Directory>
</VirtualHost>