Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess和.php?重定向_Php_.htaccess - Fatal编程技术网

.htaccess和.php?重定向

.htaccess和.php?重定向,php,.htaccess,Php,.htaccess,我正在编辑一个.htaccess文件,用于从www.oldwebsite.com重定向到www.newwebsite.com+页面的特定重定向 以下代码运行良好: RedirectPermanent /page.html http://www.newwebsite.com/newpage.html 我遇到的问题是,当我尝试重定向以redirectpermanent结尾的页面时: oldpage.php?id=1 在这一点上,我得到了一个404错误 我尝试了另一种解决方案,就是这个代码 Rew

我正在编辑一个.htaccess文件,用于从www.oldwebsite.com重定向到www.newwebsite.com+页面的特定重定向

以下代码运行良好:

RedirectPermanent /page.html http://www.newwebsite.com/newpage.html
我遇到的问题是,当我尝试重定向以redirectpermanent结尾的页面时:

oldpage.php?id=1
在这一点上,我得到了一个404错误

我尝试了另一种解决方案,就是这个代码

RewriteCond %{QUERY_STRING}   ^id=1$
RewriteRule ^oldpage\.php$ http://www.newwebsite.com/newpage2.html [R=301,L]
除非浏览器让我转到以下链接,否则此操作正常:

http://www.newwebsite.com/newpage2.html?id=1
有人能帮我解决这个问题吗。我想使用重定向永久(不起作用,重定向seether也是一样)。我认为解决方案很简单,但我想我没有得到一个细节


谢谢

只需在rewriteRule末尾添加
,即可覆盖查询字符串

RewriteCond %{QUERY_STRING}   ^id=1$
RewriteRule ^oldpage\.php$ http://www.newwebsite.com/newpage2.html? [R=301,L]

您可以使用PHP$\u SERVER['PHP\u SELF']方法进行此操作

所以

它会将重定向到


或者,您可以尝试$\u服务器['PHP\u SELF']而不是$\u服务器['REQUEST\u URL']

如果您试图删除查询字符串,可以使用


您的代码中有小的打字错误,
olpage
而不是
oldpage
。好的,但这只是一个例子,在我的例子中,它与打字错误无关。顺便问一下,除了此代码之外,还有其他解决方案可以做同样的事情吗?RedirectPermanent和其他重定向指令忽略查询字符串,因此,您无法使用它们基于查询字符串进行重定向。谢谢,我也将尝试另一个.htaccess solutionGood选项。谢谢!
$page = $_SERVER['PHP_SELF'];

header("Location: http://www.newwebsite.com$page");
RewriteCond %{QUERY_STRING}   ^id=1$
RewriteRule ^oldpage\.php$ http://www.newwebsite.com/newpage2.html? [R=301,L, QSD]