Mod_Rewrite URL

时间:2013-04-08 20:55:02

标签: php .htaccess mod-rewrite

当前网址:

http://localhost/blog/profile.php?username=Username&page_type=following

我希望它是:

http://localhost/blog/profile/Username/following

当前.htaccess:

RewriteEngine On
CheckCaseOnly On
CheckSpelling On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^profile/(.*)$ /blog/profile.php?username=$1&page_type=$2 [QSA,L]

有可能以这种方式重写吗?或者有更好的方法吗?

2 个答案:

答案 0 :(得分:0)

您需要两个捕获组:

RewriteRule ^profile/(.*?)/(.*)$ /blog/profile.php?username=$1&page_type=$2 [QSA,L]

答案 1 :(得分:0)

RewriteRule模式中的$2没有page_type

RewriteRule ^profile/(.*?)/(.*)$ /blog/profile.php?username=$1&page_type=$2 [QSA,L]