我在服务器上测试.htaccess文件。目标是将www.mysite.com/index.php?q=help
转换为mysite.com/help
1)删除www.
2)删除index.php?q=
根目录中的.htaccess包含:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?q=$1 [L]
什么都没发生 - index.php?q = help还在那里...... 有谁知道,为什么?
谢谢。
马修,再次感谢。这是另一个版本,问题解决了50%。RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [L,R=301] #removes www., works fine
RewriteRule ^index\.php/?$ http://mysite.com/ [NC,R,L] #still doesn't work - it does not remove index.php as needed
答案 0 :(得分:1)
由于RewriteCond%{REQUEST_FILENAME},原始请求仍然在那里!-f