【问题标题】:rewrite rule not working on usernames ending with letter h重写规则不适用于以字母 h 结尾的用户名
【发布时间】:2012-11-09 11:05:29
【问题描述】:

我有一个 www.amunzi.com/profile.php?username=anyusername 的重写规则

> RewriteRule ^([a-zA-Z0-9\._-]+[^.php])$ profile.php?username=$1  

> RewriteRule ^([a-zA-Z0-9\._-]+[^.php])/()$ profile.php?username=$1  

它工作正常,但问题是当用户名以字母“h”结尾时,它会给出 404 错误。

【问题讨论】:

标签: .htaccess


【解决方案1】:

这个正则表达式:^([a-zA-Z0-9\._-]+[^.php])$ 将匹配任何非空的{字母数字字符或._-} 字符串,后跟除.php 之外的任何字符。

试试这个:

RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^([a-zA-Z0-9\._-]+)$ profile.php?username=$1

重写条件应匹配所有不以.php (source) 结尾的URL,并且重写规则中的正则表达式将匹配{alphanumeric characters or ._-} 的任何非空字符串。

【讨论】:

    猜你喜欢
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多