【发布时间】:2013-05-09 10:26:21
【问题描述】:
我想用 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>
我现在正在使用它,但这还不够。谢谢
【问题讨论】:
-
好吧,向我们展示您尝试过的和无效的。此外,您应该真正使用 php 路由器脚本进行 url 重写。它将使您的 apache 配置最小且干净,并且更易于维护。