我有我的.htaccess文件中的以下内容:
<Directory /home/eamorr/sites/example.com/www> Options Indexes FollowSymLinks MultiViews Options -Indexes AllowOverride all Order allow,deny allow from all RewriteEngine on RewriteRule ^([^/.]+)/?$ index.php?uname=$1 [R,L] </Directory>
当我访问http://example.com/Eamorr时 , http://example.com/home/eamorr/sites/example.com/www/index.php?uname=Eamorr出现在地址栏中!
但我希望http://example.com/index.php?uname=Eamorr出现在地址栏中!
(我需要在index.php中parsingjavascript中的URL)
只能在服务器configuration或虚拟主机中使用<Directory>指令, 而不能在.htaccess文件中使用。
如果你使用:
RewriteRule ^([^/.]+)/?$ index.php?uname=$1 [R,L]
每个目录前缀( /home/eamorr/sites/example.com/www )会自动添加到replace中。 所以删除<Directory>指令并在开始时加一个斜线:
RewriteEngine on RewriteRule ^([^/.]+)/?$ /index.php?uname=$1 [R,L]
它会像你期望的那样工作。