如何在apache中从一个网址重定向到另一个网址

时间:2018-07-19 09:56:41

标签: apache .htaccess redirect mod-rewrite

我目前正在使用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

出现类似

的错误
    • [li> [19 / Jul / 2018:07:30:37 +0000]“ GET / HTTP / 1.1” 301252
    • [li> [19 / Jul / 2018:09:22:15 +0000]“ GET / mysoftware / HTTP / 1.1” 301252
  • [li> [19 / Jul / 2018:09:22:16 +0000]“ GET / mysoftware / index HTTP / 1.1” 301257
    • [li / 19/2018:09:22:16 +0000]“ GET / mysoftware / indexindex HTTP / 1.1” 301262
    • [li / [j / 2018/09:22:16 +0000]“” GET / mysoftware / indexindexindex HTTP / 1.1“ 301 267
    • [li> [19 / Jul / 2018:09:22:17 +0000]“ GET / mysoftware / indexindexindexindex HTTP / 1.1” 301 272
    • [li> [19 / Jul / 2018:09:22:17 +0000]“ GET / mysoftware / indexindexindexindexindex HTTP / 1.1” 301277
    • [li / 19/2018:09:22:17 +0000]“ GET / mysoftware / indexindexindexindexindexindexindex HTTP / 1.1” 301282
    • [li> [19 / Jul / 2018:09:22:18 +0000]“ GET / mysoftware / indexindexindexindexindexindexindexindex HTTP / 1.1” 301287
    • [li / [Jul / 2018:09:22:18 +0000]“获取/ mysoftware / indexindexindexindexindexindexindexindexindex HTTP / 1.1” 301292
    • [19 / Jul / 2018:09:22:19 +0000]“ GET / mysoftware / indexindexindexindexindexindexindexindexindexindex HTTP / 1.1” 301297
    • [li> [19 / Jul / 2018:09:22:19 +0000]“ GET /mysoftware/indexindexindexindexindexindexindexindexindexindexindexindexHTTP/1.1” 301302
    • [li> [19 / Jul / 2018:09:22:19 +0000]“ GET / mysoftware / indexindexindexindexindexindexindexindexindexindexindexindexindex HTTP / 1.1” 301307
    • [li> [19 / Jul / 2018:09:22:20 +0000]“ GET / mysoftware / indexindexindexindexindexindexindexindexindexindexindexindexindex HTTP / 1.1” 301312
    • [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” 301322

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

1 个答案:

答案 0 :(得分:0)

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

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

让我知道是否还有更好的方法?