我想用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>
我现在正在使用它,但这还不够。感谢
答案 0 :(得分:0)
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: