简体   繁体   English

用Apache URL重写正则表达式

[英]URL Rewrite regex with apache

I have a .htaccess file. 我有一个.htaccess文件。 I can generate my custom url. 我可以生成我的自定义网址。 In my .htaccess file 在我的.htaccess文件中

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

I can use my profile page mysite.com/username with rules which is above. 我可以将个人资料页面mysite.com/username与上述规则一起使用。 My awish.php page does not work like: 我的awish.php页面无法正常工作:

mysite.com/p/awish/43242 mysite.com/p/awish/43242

But it works when I call mysite.com/p/awish/ without id. 但是,当我不带id致电mysite.com/p/awish/时,它就可以工作。

Your regex is not supporting URI p/awish/43242 . 您的正则表达式不支持URI p/awish/43242 You can use: 您可以使用:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM