【问题标题】:Htaccess with 2 different url parameters?Htaccess 有 2 个不同的 url 参数?
【发布时间】:2016-05-22 05:51:16
【问题描述】:

这是我当前的.htaccess,它重定向诸如 domain.com/name 之类的请求 到 domain.com/art.php?name.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule   ^(.*) art.php?$1 [L]

现在我想将 domain.com/name/pay 重定向到 domain.com/pay.php?name 如何将它添加到我当前的 htaccess 中?

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您可以使用由 / 分隔的 2 个正则表达式捕获组“(.+)”来捕获 uri 的 2 部分:

    RewriteEngine on
    
    #--Don't rewrite real files and directories--#
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #--Rewrite everything else to /art.php--#
    RewriteRule ^(.+?)/(.+)$ pay.php?$1=$2 [NC,L]
    

    【讨论】:

    • 这不是我想做的,如果有 /name/pay 我想将它重定向到 pay.php
    • @User77431 好的,我更改了目标网址。
    【解决方案2】:

    【讨论】:

    • 这肯定应该在 cmets 中?从技术上讲,这不是问题的答案......
    猜你喜欢
    • 2019-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 2015-11-12
    相关资源
    最近更新 更多