2
Options +Indexes
# or #
IndexIgnore *
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1 
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?u=$1

我想在重写规则中添加点,以便它们之间带有点的用户名像 rahul.kapoor 一样工作,但 rahulkapoor 工作,请帮忙。

4

2 回答 2

2

尽管点通常在正则表达式中具有特殊含义,但在字符类中使用时它不是元字符,因此在您的情况下,您可以使用:

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

请注意,我已将末尾的正斜杠设为可选,因此您只需使用一行而不是两行。

编辑:您还可以使用元字符一词来进一步简化它:

RewriteRule ^([\w.-]+)/?$ profile.php?u=$1
于 2013-10-13T15:30:38.253 回答
0

.htaccess对于文件中使用的正则表达式,点字符具有特殊含义。它的意思是“(几乎)任何字符”。

如果您想使用“真正的”点字符,则必须使用反斜杠对其进行转义:

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

我在这里所做的是更改您的正则表达式规则以匹配:

  1. 多个字母数字字符[a-zA-Z0-9_-]+
  2. 一个可选的点字符\.?
  3. 更多(可选)字母数字字符[a-zA-Z0-9_-]*
于 2013-10-13T15:17:17.983 回答