我只是希望 feature.php?id=1 更改为 feature/1
mod_rewrite 根据 php 启用。我尝试将垃圾放入 .htaccess 文件中,这给了我一个 500 错误,所以我猜那也可以。
我的虚拟主机文件:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/htdocs"
ServerName test2
DirectoryIndex index.php
<Directory "C:/htdocs">
AllowOverride All
Allow from All
</Directory>
RewriteLog "C:/xampp/apache/logs/rewrite.log"
RewriteLogLevel 9
</VirtualHost>
我的.htaccess文件的内容
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/?feature/([a-zA-Z0-9]+)$ /feature.php?id=$1 [L,QSA]
</IfModule>
以及rewrite.log的内容
127.0.0.1 - - [19/Oct/2012:12:23:17 +0100] [test2/sid#2006540][rid#66156b0/initial] (3) [perdir C:/htdocs/] 剥离每个目录前缀: C:/htdocs/feature.php -> feature.php
127.0.0.1 - - [19/Oct/2012:12:23:17 +0100] [test2/sid#2006540][rid#66156b0/initial] (3 ) [perdir C:/htdocs/] 将模式 '^/?feature/([a-zA-Z0-9]+)$' 应用于 uri 'feature.php'
127.0.0.1 - - [2012 年 10 月 19 日: 12:23:17 +0100] [test2/sid#2006540][rid#66156b0/initial] (1) [perdir C:/htdocs/] 通过 C:/htdocs/feature.php