.htaccess htaccess:包含文本或文本/数字的url规则

.htaccess htaccess:包含文本或文本/数字的url规则,.htaccess,url-rewriting,.htaccess,Url Rewriting,应将用户重定向到: mywebsite.com/index.php?section=$1&subsection=$2 重写的URL可以是: mywebsite.com/profile/john-doe 或 所以我认为正确的规则应该是: ^([-/$a-z]+)\/([-/$a-z0-9]+)$ 但似乎如果mywebsite.com/profile/john-doe-52运行良好,而mywebsite.com/profile/john-doe却无法完成这项工作 我不明白什么?在您的.

应将用户重定向到:

mywebsite.com/index.php?section=$1&subsection=$2
重写的URL可以是:

mywebsite.com/profile/john-doe

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

^([-/$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=$1&subsection=$2 [L,QSA]
您可以使用:

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