首页 > 解决方案 > htaccess 正则表达式匹配用户名 url

问题描述

我需要在 url 中使用用户名

domain.com/用户名

所以我把这一行作为 htaccess 中的最后一行,以避免与其他页面发生冲突。

RewriteRule ^([a-zA-Z0-9.]+)/?(i.html)?$  index.php?module=profile&username=$1 [QSA,L]

但问题是当我请求domain.com/manage/并继续到最后一行时,下面的行被忽略了,这导致了冲突。

RewriteRule ^manage/?(i.html)?$  manage.php?module=manage [QSA,L]

有没有办法让最后一个模式做到这一点:

/ (staticname|或任何其他静态页面的名称|) /i.html =不正常

/ fstaticname /i.html = OK作为用户名

/ staticnamef /i.html = OK作为用户名

/staticname.f /i.html = OK作为用户名

/ staticname = OK作为用户名

如果没有,还有其他解决方案吗?

谢谢你!

编辑 :

我得到这个正则表达式

^((?!(manage|notifs|admin)\/?$)([a-zA-Z0-9.]+))\/?(i.html)?$

它在正则表达式测试器中工作正常,但不适用于 htaccess。

标签: regex.htaccessurl

解决方案


推荐阅读