许多.htaccess重写规则

时间:2013-08-06 13:37:38

标签: .htaccess mod-rewrite url-rewriting

如何在.htaccess中制作这些重写规则?

www.mysite.com/123 -> www.mysite.com/project.php?id=123
www.mysite.com/123/ -> www.mysite.com/project.php?id=123
www.mysite.com/about -> www.mysite.com/about/
www.mysite.com/about/ -> www.mysite.com/about/
www.mysite.com/123.php -> www.mysite.com/123.php

1 个答案:

答案 0 :(得分:1)

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^([0-9]+)/?$ /project.php?id=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /$1/ [L,R=301]