如何在.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
答案 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]