【问题标题】:.htaccess get entire query string to a variable.htaccess 获取整个查询字符串到一个变量
【发布时间】:2014-10-18 06:58:54
【问题描述】:

我正在使用我的 .htaccess 将 Authorization 标头重写为 get 参数。我这样做的原因描述为here

所以我的问题是,当我在请求 API 时使用查询字符串时,旧的查询字符串会从 URL 中删除。我想要做的是附加一个名为“授权”的查询,而不是像这里所做的那样重写我的 index.php 后面的所有内容。

RewriteEngine on
RewriteBase /api/

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L, QSA]

RewriteCond %{HTTP:Authorization} ^Basic.*

RewriteRule ^ index.php?Authorization=%{HTTP:Authorization} [L]

有什么想法吗?

【问题讨论】:

  • 为什么在第二次重写中不使用QSA 标志?
  • 当我附加 QSA 时,我得到了 500。我可能需要更改 rewriteRule 吗?我绝对不是 .htaccess 和重写的大师。

标签: regex apache .htaccess mod-rewrite query-string


【解决方案1】:

这样吧:

RewriteEngine on
RewriteBase /api/

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L,QSA]

RewriteCond %{HTTP:Authorization} ^Basic.*
RewriteCond %{QUERY_STRING} !Authorization=[^&]*
RewriteRule ^ index.php?Authorization=%{HTTP:Authorization} [L,QSA]

【讨论】:

  • 谢谢伙计!您是否从我的推文中找到了我的问题,或者您只是幸运地找到了这个问题? :)
  • 是的,我收到了你的推文,并通过标签 .htaccess 找到了这个问题。
猜你喜欢
  • 2012-01-02
  • 1970-01-01
  • 2014-01-26
  • 2017-09-19
  • 2011-03-07
  • 2014-08-18
  • 1970-01-01
  • 1970-01-01
  • 2015-12-26
相关资源
最近更新 更多