首页 文章

htaccess通用重写规则

提问于
浏览
0

我有以下重写设置:

RewriteRule r/(.*) scripts/report.php?cp=1&id=$1

它很适合重定向mydomain.com/r/123abc,但它重定向服务器上以“r”开头的所有页面 . 当网址为mydomain.com/r/时,是否有人知道我如何才能使这个更具体到仅重定向?我应该注意,我需要保持这种通用性,所以我不能在规则中包含mydomain.com .

3 回答

  • 0

    尝试将 ^/ 放在 r/(.*) 重写规则的前面 . 这将使它:

    RewriteRule ^/r/(.*) scripts/report.php?cp=1&id=$1
    
  • 0

    我不确定这是否适合你(未经测试),但试试看:

    # Rewrite ini
    RewriteEngine on
    RewriteBase /mydomain.com/
    
    # Redirect all /mydomain.com/r/* calls to scripts/report.php
    RewriteRule ^r/(.*)$ scripts/report.php?cp=1&id=$1 [QSA]
    

    希望有所帮助 .

  • 0

    您应该指定RegEx应该与整个字符串匹配,而不是仅匹配字符串 . 您可以使用 ^$ 符号执行此操作:

    RewriteRule ^r/(.*)$ scripts/report.php?cp=1&id=$1
    

相关问题