【发布时间】: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