【问题标题】:Basic .htaccess rewrite rule issue基本 .htaccess 重写规则问题
【发布时间】:2021-09-08 08:30:15
【问题描述】:

我正在尝试使用 .htaccess 文件设置一些规则:

我想要任何这种类型的 url: / 转发到 index.php?name=X 和任何带有 /postalcode/(anything here) 的 url 转发到 index.php?postalcode=(anything here)

这是我所做的:

RewriteRule ^([^/]*)/$ index.php?name=$1 [L]
RewriteRule ^([^/postalcode/]*)/$ index.php?postalcode=$1 [L]

第一个规则有效,但第二个无效。 有什么帮助吗?

谢谢。

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    让你的 .htaccess 像这样:

    RewriteEngine On
    
    # skip all files and directories from rewrite rules below
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]
    
    # postal code handler
    RewriteRule ^postalcode/([^/]+)/?$ index.php?postalcode=$1 [L,QSA,NC]
    
    # name handler
    RewriteRule ^([^/]+)/?$ index.php?name=$1 [L,QSA]
    

    【讨论】:

      猜你喜欢
      • 2014-07-17
      • 2014-01-23
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      相关资源
      最近更新 更多