【发布时间】:2021-03-24 09:00:39
【问题描述】:
我有一个名为example.com/profiles/?id=(Any id/number that has a profile) 的网址。我想将此 URL 更改为用户友好的 URL,如下所示:
example.com/profiles/2
我尝试过像这样重写.htaccess:
RewriteEngine On
RewriteRule ^/profiles/username/([\d]+)$ profiles.php?id=$1
我也试过这个:
RewriteEngine On
RewriteRule ^/profiles/([0-9]+)\.html /profiles/?id=$1
这两种方法都失败了。我已经有一个终止文件扩展名的重写规则。我不明白为什么我的友好 URL 不起作用。
【问题讨论】:
-
重写规则 ^/profiles/([0-9]+) /profiles/?id=$1
-
@Farkie 这在
.htaccess中仍然不起作用,因为 URL 路径上的斜杠前缀。
标签: php .htaccess mod-rewrite