【问题标题】:Convert path queries to url variables with .htaccess?使用 .htaccess 将路径查询转换为 url 变量?
【发布时间】:2013-04-28 20:08:23
【问题描述】:

我想将“http://www.mysite.com/users”之类的实体查询转换为“http://www.mysite.com/entities.php?entityName=users”。

如何制定这样的重写规则?或者我应该在我的 .htaccess 中添加什么?

保留原始 url 变量会很棒,例如将“http://www.mysite.com/users?fields=ID,UUID”转换为“http://www.mysite.com/entities.php?entityName=users&fields=ID,UUID”。

【问题讨论】:

    标签: .htaccess http url redirect url-rewriting


    【解决方案1】:

    如果你想重写 (而不是重定向) /$users/entities.php?entityName=$users 同时保留原始查询字符串,例如将 /$users?fields=ID,UUID 重写为 /entities .php?entityName=$users&fields=ID,UUID 那么你可以试试这个:

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-zA-Z0-9_-]+)/?$ /entities.php?entityName=$1 [QSA]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-10
      • 2020-04-16
      • 1970-01-01
      相关资源
      最近更新 更多