【问题标题】:Mod Rewrite Pattern Issue [duplicate]Mod重写模式问题[重复]
【发布时间】:2012-10-11 13:40:37
【问题描述】:

可能重复:
What literal characters should be escaped in a regex?

RewriteRule ^profile/[A-Za-z_-\d\^\.]/*$ ./index.php?page=showuser&username=$1

我是 mod 重写的新手。有人可以告诉我我的模式有什么问题吗?我试图只让传入的名称包含字符、数字、-、^、_ 和 .符号,但当我使用该语法时它会给我一个错误。

【问题讨论】:

  • 它给我的错误是“找不到对象!”。我正在本地主机上工作。

标签: php mysql regex .htaccess


【解决方案1】:

4 件事:

  • 开头缺少斜杠
  • 你在你的角色类之后忘记了+ :)
  • 你也忘了捕获用户名:p
  • 您应该始终将 - 字符放在字符类中的类开头

(另外,你不需要在字符类中转义除] 之外的任何内容)

RewriteRule ^/profile/([-A-Za-z_\d^.]+)/*$ ./index.php?page=showuser&username=$1

【讨论】:

  • 问题已解决。非常感谢!
【解决方案2】:

试试

RewriteRule ^profile/([\w\d\.^_-]+)/?$ ./index.php?page=showuser&username=$1

使用起来可能会更好

RewriteRule ^profile/([\w\d\.^_-]+)/?$ /index.php?page=showuser&username=$1

如果您的 index.php 文件位于公用文件夹的顶部(根)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多