Php Mod rewrite问题用post重定向
事实上,我正在编写一个小的php脚本,现在我正在努力使用mod rewrite进行重定向。 我想要的是重定向Php Mod rewrite问题用post重定向,php,apache,mod-rewrite,Php,Apache,Mod Rewrite,事实上,我正在编写一个小的php脚本,现在我正在努力使用mod rewrite进行重定向。 我想要的是重定向 www.xx.com/motivational/api.php?latest=1 到 我试过这个,但不起作用: RewriteRule ^/motivational/api\.php$ /api.php?latest=&%{QUERY_STRING} 您无法在RewriteRule中匹配查询字符串,您将需要RewriteCond来匹配url中的查询字符串: RewriteE
www.xx.com/motivational/api.php?latest=1
到
我试过这个,但不起作用:
RewriteRule ^/motivational/api\.php$ /api.php?latest=&%{QUERY_STRING}
您无法在RewriteRule中匹配查询字符串,您将需要RewriteCond来匹配url中的查询字符串:
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^/]+)/api\.php\?latest=1 [NC]
RewriteRule ^ /api.php?latest=1&app=%1 [NC,L,R]
%1是RewriteCond中正则表达式“([^/]+)”的一部分,它在请求行中包含动态捕获的路径。
%{QUERY\u STRING}
表示整个查询字符串,在您的例子中是latest=1
。因此,当您将其附加到替换字符串中的…?latest=
时,结果是…?latest=latest=1
,这不是您想要的结果
将规则更改为
RewriteRule ^/motivational/api\.php$ /api.php?%{QUERY_STRING}&app=motivational
你应该没事的
或者你可以:
RewriteRule ^/motivational/api\.php$ /api.php?app=motivational [QSA]
QSA
标志意味着将新的查询字符串附加到旧的查询字符串,而不是替换它,这样您的最新的
变量就不会丢失
RewriteRule ^/motivational/api\.php$ /api.php?app=motivational [QSA]