2012-01-05 87 views
0

的http:// domain.com/index.php - > HTTP:// domain.com/ - OKhtaccess的 - 删除的index.php,但不是的index.php时的index.php Z = ABC

http:// domain.com/index.php?z=abc - > http:// domain.com/index.php?z=abc - 不行,保持不变。 这个工程使用下面的代码:

RewriteEngine On 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/ 
RewriteRule ^(.*)index\.php$ /$1 [R=301,L] 

如何修改这个代码,以便

http:// domain.com/index.php?z=abc -> http:// domain.com/?z=abc 

回答

1

Apache会自动照顾查询字符串。所有你需要的是这样的:

RewriteEngine on 
RewriteRule ^index.php/[L,R=301] 
+0

作品修改完善的RewriteCond以及!谢谢! – Haradzieniec 2012-01-07 08:57:59

+0

[R = 301]会中断POST请求(表单数据丢失),但将其保留不会影响地址栏。出于这个原因,如果(永远)发布到索引,你会想避免做这种重写。 – Umbrella 2012-01-11 21:49:00

+0

@伞大多数服务器默认为301,无论如何。而且由于他不希望'/ index.php'显示在地址栏中,我怀疑他会发布到它。 – kba 2012-01-11 22:25:39

1

尝试以下

RewriteEngine On 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php(\?[^\ ]*)?\ HTTP/ 
RewriteRule ^(.*)index\.php$ /$1 [R=301,L] 
+0

谢谢!!!!!! – Haradzieniec 2012-01-07 08:53:03