【发布时间】:2019-01-20 04:46:06
【问题描述】:
我已经使用了这个 htaccess 规则并且它有效
RewriteRule ^community/profile/([^/]+) community/profile/profile.php?id=$1
因此,当我在个人资料页面(例如 website.com/community/profile/example-user)上时,我将能够从 id=$1 部分中提取用户。
我需要将此扩展到两个文件夹,其中 example-user 可以有 2 个子文件夹,例如 website.com/community/profile/example-user/folder1/ 和 website.com/community/profile/example-user/folder 2/
我尝试了以下规则:
RewriteRule ^community/profile/([^/]+)/([^/]+) community/profile/profile.php?id=$1&car=$2
不幸的是,这违反了整个规则并且不起作用。我从这篇帖子https://webmasters.stackexchange.com/questions/65785/rewrite-up-to-three-folders-into-three-query-string-parameters-to-a-php-script得到了这个想法
我也试过了
RewriteRule ^community/profile/../([^/]+) community/profile/profile?id=$1&car=$2
也没有用。
为了清楚起见,如果一个人只进入“第一个”文件夹,在这个例子中是/example-user/,汽车变量应该是空的。如何编写此规则,以便将第二个“文件夹”放入第二个变量中,以便稍后在我的 php 文件中提取它?
【问题讨论】:
标签: php .htaccess url-rewriting