.htaccess重定向并保留文件名,不带文件扩展名

时间:2014-12-03 08:15:50

标签: php .htaccess redirect url-rewriting query-string

我正在重定向,但现在我想保留文件名以使其类似于目录。

我会添加一个带有文件名的查询字符串,将其添加到重定向网址,但这没有多大意义。

例如

RewriteCond %{THE_REQUEST} \ /+profile\.php\?user=([^&]+)&uid=([^&\ ]+)
RewriteRule ^ /%1/%2? [L,R=301]

内部

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

重定向到www.site.com/username/uid

我希望这是www.site.com/profile/username/uid

我会添加第三个查询字符串,例如www.site.com/profile.php?user=username&uid=45&profile,但它没有多大意义。

1 个答案:

答案 0 :(得分:1)

您可能会略微修改重写规则。

  RewriteCond %{THE_REQUEST} \ /+profile\.php\?user=([^&]+)&uid=([^&\ ]+) 
  RewriteRule ^ /profile/%1/%2? [L,R=301]

内部。

  RewriteRule ^profile/([^/]+)/([^/]+)$ profile.php?user=$1&uid=$2 [L,QSA]
相关问题