htaccess从website.com/?u=1&name=john重定向到website.com/1/john

时间:2014-10-13 10:51:40

标签: php apache .htaccess mod-rewrite

找到了这个,但我想要查询完成的字符串。

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+profile\.php\?u=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ profile.php?u=$1 [L,QSA]

1 个答案:

答案 0 :(得分:0)

为2个参数添加新的重定向和重写规则:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+profile\.php\?u=([^\s&]+)&name=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]

RewriteCond %{THE_REQUEST} \s/+profile\.php\?u=([^\s&]+)\s [NC]
RewriteRule ^ /%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/?$ profile.php?u=$1&name=$2 [L,QSA]

RewriteRule ^([^/]+)/?$ profile.php?u=$1 [L,QSA]