htaccess : url 带文本的规则或 text/number

htaccess : url rule with text or text/number

用户应该被重定向到:

mywebsite.com/index.php?section=&subsection=

重写的 URL 可以是:

mywebsite.com/profile/john-doe

mywebsite.com/profile/john-doe-52

所以我认为正确的规则是:

^([-/$a-z]+)\/([-/$a-z0-9]+)$

但似乎如果 mywebsite.com/profile/john-doe-52 运行良好,当 mywebsite.com/profile/john-doe 不运行时'不做这个工作。

我不明白什么?

在您的 .htaccess 文件中

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^\.*]+)/([A-Za-z0-9-]+)/?$ index.php?section=&subsection= [L,QSA]

您可以使用:

RewriteRule ^(\w+)/([-$a-z0-9]+)/?$ index.php?section=&subsection= [L,QSA]