0

如何在 .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
4

1 回答 1

1

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_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]
于 2013-08-06T13:42:15.957 回答