我想用apache mod_rewrite:做四件事
-
删除www
http://www.example.com/ >>> http://example.com/
-
删除index.php
http://example.com/index.php >>> http://example.com/
-
重写URI
http://example.com/index.php?rewrite=request >>> http://example.com/request
-
删除最后一个斜线
http://example.com/request/ >>> http://example.com/request
我读过很多例子,但没有一个能正常工作。
编辑:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteRule ^([^/.]+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^([^/.]+)$ index.php?rewrite=$1 [L]
</IfModule>
我现在用这个,但还不够。感谢
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com
RewriteRule (.*)http://www.example.com/$1 [R=301,L]
RewriteRule ^([^/.]+)/$ http:// %{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^([^/.]+)$ index.php?rewrite=$1 [L]
或
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} index.php HTTP
RewriteRule ^index.php$ http:// www.example.com/ [R=301,L]
使用apache mod_rewrite: