【问题标题】:How to redirect from one url to another url in apache如何在apache中从一个url重定向到另一个url
【发布时间】:2023-03-20 06:12:02
【问题描述】:

我目前使用 Apache/2.2.15 作为 Web 服务器,我在 apache 层中遇到了关于重定向功能的问题。

我的要求是从https://hostname/mysoftware 重定向或 https://hostname/mysoftware/https://hostname/mysoftware/index

同样,我在 apache 配置文件中添加了以下条目,尝试同时使用 Redirect 和 RedirectMatch 没有按预期工作

它不断将索引页面附加到 URL

重定向永久/mysoftware https://hostname/mysoftware/index

RedirectMatch 永久/mysoftware https://hostname/mysoftware/index

RedirectMatch 永久 /mysoftware/ https://hostname/mysoftware/index

RedirectMatch 永久 /mysoftware/ https://hostname/mysoftware/index

得到类似的错误

    • [19/Jul/2018:07:30:37 +0000] "GET / HTTP/1.1" 301 252
    • [19/Jul/2018:09:22:15 +0000] "GET /mysoftware/HTTP/1.1" 301 252
  • [19/Jul/2018:09:22:16 +0000] "GET /mysoftware/index HTTP/1.1" 301 257
    • [19/Jul/2018:09:22:16 +0000] "GET /mysoftware/indexindex HTTP/1.1" 301 262
    • [19/Jul/2018:09:22:16 +0000] "GET /mysoftware/indexindexindex HTTP/1.1" 301 267
    • [19/Jul/2018:09:22:17 +0000] "GET /mysoftware/indexindexindexindex HTTP/1.1" 301 272
    • [19/Jul/2018:09:22:17 +0000] "GET /mysoftware/indexindexindexindexindexindex HTTP/1.1" 301 277
    • [19/Jul/2018:09:22:17 +0000]“GET /mysoftware/indexindexindexindexindexindexindex HTTP/1.1”301 282
    • [19/Jul/2018:09:22:18 +0000]“GET /mysoftware/indexindexindexindexindexindexindexindex HTTP/1.1”301 287
    • [19/Jul/2018:09:22:18 +0000] "GET /mysoftware/indexindexindexindexindexindexindexindexindexindex HTTP/1.1" 301 292
    • [19/Jul/2018:09:22:19 +0000]“GET /mysoftware/indexindexindexindexindexindexindexindexindexindexindexHTTP/1.1”301 297
    • [19/Jul/2018:09:22:19 +0000] "GET /mysoftware/indexindexindexindexindexindexindexindexindexindexindexindexHTTP/1.1" 301 302
    • [19/Jul/2018:09:22:19 +0000] “GET /mysoftware/indexindexindexindexindexindexindexindexindexindexindexindexindexHTTP/1.1”301 307
    • [19/Jul/2018:09:22:20 +0000]“GET /mysoftware/indexindexindexindexindexindexindexindexindexindexindexindexindexindexHTTP/1.1”301 312
    • [19/Jul/2018:09:22:20 +0000] "GET /mysoftware/indexindexindexindexindexindexindexindexindexindexindexindexindexindex HTTP/1.1" 301 317
    • [19/Jul/2018:09:22:21 +0000] “GET /mysoftware/indexindexindexindexindexindexindexindexindexindexindexindexindexindexindex HTTP/1.1”301 322

那么任何人都可以指导我在这里犯了什么错误以及如何纠正这个问题

【问题讨论】:

  • Redirect/ RedirectMatch 仅适用于路径 prefix,其余部分会自动附加到目标 URL。你真的应该在这里使用 mod_rewrite,而不是 Redirect 指令。

标签: apache .htaccess redirect mod-rewrite


【解决方案1】:

我找到了一个解决方案,它正在工作

RedirectMatch 永久 ^/mysoftware/?$ https://hostname/mysoftware/index

让我知道是否有更好的方法来做到这一点?

【讨论】:

    猜你喜欢
    • 2015-12-29
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多