Apache重定向到一个干净的URL [英] Apache redirect to a clean URL
问题描述
我有一个使用Apache / 2.2.15的centos Web服务器。过去,我有这样的登录页面 http://app.website.com/index .php?resource = Login ,现在我更改了网站,并希望将此页面重定向到新页面。我在虚拟主机中放置了此重定向:
I have a centos webserver with Apache/2.2.15. In the past I had la login page like this http://app.website.com/index.php?resource=Login and now I changed my website and I want to redirect this page to the new one. I puted in virtual host this redirect:
RedirectPermanent / https://newapp.website.com/
现在当我访问此页面时 http://app.website.com/index.php?resource=登录我被重定向到此页面 http://newapp.website.com/index.php?resource=Login ,我收到404。
但我想重定向我使用干净的网址,没有
And now when I access this page http://app.website.com/index.php?resource=Login I am redirected to this page http://newapp.website.com/index.php?resource=Login and I receive 404. But I want to redirect me to the clean url, without "index.php?resource=Login" just http://newapp.website.com/. I want to solve this porblem because many users bookmarked the login page and now they receive 404 error. I will not change the website, I need a solution in apache or in .htaccess. Thanks
推荐答案
重定向指令将跟踪路径和查询字符串附加到其目标网址,尝试使用mod_rewrite解决此问题:
Redirect Directive appends trailing paths and query strings to its destination Url, Try mod_rewrite to solve this problem :
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php\?resource=Login [NC]
RewriteRule ^ http://newapp.website.com/? [NC,L,R]
最后的空问号很重要,因为它会丢弃原始的网址中的查询字符串。
Empty question mark at the end is important as it will discard the original query string from url.
这篇关于Apache重定向到一个干净的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!