URL 用 apache 重写正则表达式

URL Rewrite regex with apache

我有一个 .htaccess 文件。我可以生成我的自定义 url。在我的 .htaccess 文件中

RewriteRule ^([\w-]+)/?$ profile.php?username= [QSA,L]
RewriteRule ^p/([\w-]+)/?$ awish.php?wishId= [QSA,L]

我可以按照上面的规则使用我的个人资料页面 mysite。com/username。 我的 awish.php 页面无法正常工作:

mysite.com/p/awish/43242

但是当我在没有 id 的情况下调用 mysite.com/p/awish/ 时它起作用了。

您的正则表达式不支持 URI p/awish/43242。您可以使用:

RewriteRule ^([\w-]+)/?$ profile.php?username= [QSA,L]

RewriteRule ^p/([\w-]+)/(\d+)/?$ .php?wishId= [QSA,L,NC]