修复 Apache Web 服务器重写后的重定向

Fix redirect after rewrite in Apache web server

提问人:Julian 提问时间:9/16/2023 更新时间:9/16/2023 访问量:20

问:

我使用单页应用程序动态创建了页面,其 URL 类似于 https://oga.org.uk/boat_register/boat/?oga_no=3511

我在 /boat_register 中安装了以下 .htaccess 文件:

Options -Multiviews
RewriteEngine on
RewriteBase /boat_register/

RewriteRule ^boat/([0-9]+)/?$ /boat_register/boat?oga_no=$1 [QSA,L]

这使得基于路径的 URL 可以工作,因此船只可以通过 https://oga.org.uk/boat_register/boat/?oga_no=3511https://oga.org.uk/boat_register/boat/3511 访问。

我试图让 https://oga.org.uk/boat_register/boat/3511 URL 成为 URL 栏中显示的 URL,但我发现没有一个食谱对我有用。它仍然 301 重定向到原始 URL。我可以对 .htaccess 文件执行什么操作和/或对核心 Apache 配置进行更改,以使其看起来像基于路径的 URL 是真实的?

这是服务器对基于路径的请求的响应:

> GET /boat_register/boat/3511 HTTP/2
> Host: oga.org.uk
> User-Agent: curl/8.1.2
> Accept: */*
> 
< HTTP/2 301 
< content-type: text/html; charset=iso-8859-1
< server: Apache
< location: http://oga.org.uk/boat_register/boat/?oga_no=3511
< x-origin-cache-status: HIT
< date: Sat, 16 Sep 2023 06:21:46 GMT
< x-via: LHR2
< x-cdn-node-is-at-origin: 1
< x-cdn-cache-status: HIT
< 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://oga.org.uk/boat_register/boat/?oga_no=3511">here</a>.</p>
</body></html>
Apache .htaccess 重定向 mod-rewrite

评论

0赞 CBroe 9/18/2023
仅此一项就不应该重定向。您的 .htaccess 中还有更多(与 URL 重写相关)而不仅仅是这些行?
0赞 Julian 10/9/2023
我不知道 - 据我所知,我列出的文件是已安装的文件。(对不起,只是注意到你的评论)。

答: 暂无答案