Php Mod_重写URL

Php Mod_重写URL,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,当前URL: http://localhost/blog/profile.php?username=Username&page_type=following 我希望它是: http://localhost/blog/profile/Username/following 当前访问权限: RewriteEngine On CheckCaseOnly On CheckSpelling On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{

当前URL:

http://localhost/blog/profile.php?username=Username&page_type=following
我希望它是:

http://localhost/blog/profile/Username/following
当前访问权限:

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]

可以这样重写吗?还是有更好的办法

您需要两个捕获组:

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

模式中的
页面类型
没有
$2