我的链接看起来像这样:
http://localhost/account/index.php?key=changepassword
http://localhost/account/index.php?key=changeemail
http://localhost/library/index.php?key=nemesis
http://localhost/library/index.php?key=books
我怎么能把它们改写成:
http://localhost/account/changepassword
http://localhost/account/changeemail
http://localhost/library/nemesis
http://localhost/library/books
答案 0 :(得分:0)
通过httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在.htaccess
目录下的DOCUMENT_ROOT
中:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(account)/(.+?)/?$ /$1/index.php?key=$2 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(library)/(.+?)/?$ /$1/index.php?key=$2 [L,QSA,NC]