Apache 使用可选查询字符串(.htaccess)重定向

Apache 使用可选查询字符串(.htaccess)重定向,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我已经编写了一个小的PHP脚本,用它我有一个类似于短url的东西 short.url/string 指向 short.url/redirect.php?id=string 代码: 其中一些短URL具有查询字符串;不幸的是,我很难将查询字符串与上面的代码结合起来 short.url/string?查询 应该被引导到 short.url/redirect.php?id=string&q=query 我该怎么做呢?您需要在规则中使用QSA(查询字符串附加)标志 QSA标志用于组合新查询字符串和旧查询字

我已经编写了一个小的PHP脚本,用它我有一个类似于短url的东西

short.url/string

指向

short.url/redirect.php?id=string

代码:

其中一些短URL具有查询字符串;不幸的是,我很难将查询字符串与上面的代码结合起来

short.url/string?查询

应该被引导到

short.url/redirect.php?id=string&q=query

我该怎么做呢?

您需要在规则中使用QSA(查询字符串附加)标志

QSA标志用于组合新查询字符串和旧查询字符串

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^(.+)$ ./redirect.php?id=$1 [QSA]
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^(.+)$ ./redirect.php?id=$1 [QSA]