【问题标题】:Apache redirect to a clean URLApache 重定向到一个干净的 URL
【发布时间】:2016-02-22 02:45:27
【问题描述】:

我有一个 Apache/2.2.15 的 centos 网络服务器。过去我有这样的登录页面http://app.website.com/index.php?resource=Login,现在我更改了我的网站,我想将此页面重定向到新页面。我把这个重定向放在虚拟主机中:

RedirectPermanent / https://newapp.website.com/

现在,当我访问此页面 http://app.website.com/index.php?resource=Login 时,我被重定向到此页面 http://newapp.website.com/index.php?resource=Login 并收到 404。 但我想将我重定向到干净的 url,没有“index.php?resource=Login”只是http://newapp.website.com/。我想解决这个问题,因为许多用户为登录页面添加了书签,现在他们收到 404 错误。我不会更改网站,我需要 apache 或 .htaccess 中的解决方案。谢谢

【问题讨论】:

    标签: apache .htaccess redirect centos


    【解决方案1】:

    重定向指令将尾随路径查询字符串附加到其目标Url,尝试mod_rewrite来解决这个问题:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} /index\.php\?resource=Login [NC]
    RewriteRule ^  http://newapp.website.com/? [NC,L,R]
    

    末尾的空问号很重要,因为它会丢弃 url 中的原始查询字符串。

    【讨论】:

      猜你喜欢
      • 2013-07-04
      • 1970-01-01
      • 2023-03-22
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多