.htaccess URL重写以匹配符号,字母和数字



我正在尝试重写此URL:

localhost/classifieds/index.php?page=activate&extra=$2y$10$LsV9m8JgEz2zMaJYRNqocuOzaqR8oHmn3tBIjIQv.TI4JWd3rWVrC

to:

localhost/classifieds/activate/$2y$10$LsV9m8JgEz2zMaJYRNqocuOzaqR8oHmn3tBIjIQv.TI4JWd3rWVrC

现在,如果我输入:

,第一部分是成功的
localhost/classifieds/activate

它给了我:

localhost/classifieds/index.php?page=activate

特此,加载正确的控制器。

我的主要问题是我希望该规则还可以重写URL的第二部分。

我尝试了不同的正则配合组合,但无济于事。

为了使classifieds/activate/whatever默默击中index.php?page=activate&extra=whatever,您需要这样的东西:

Options +FollowSymLinks
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    # Match the host, if you wish
    #RewriteCond %{HTTP_HOST} ^localhost$
    RewriteRule classifieds/activate/(.*) index.php?page=activate&extra=$1 [L]
</IfModule>

如果要传递任何查询字符串参数,则需要将QSA标志添加到重写规则的末尾。

如果您愿意,可以在线测试。

如果您需要更通用的重写规则将URI的第二部分(在这种情况下为activate)重写为page参数,则是您需要的:

RewriteRule classifieds/(.*)/(.*) index.php?page=$1&extra=$2 [L]

您可以更具体地说明自己想期望的角色;将(.*)([0-9A-Za-z])(w)之类的东西交换以接受字母数值。

最新更新