智能重定向
Intelligent redirection
我是使用 Apache 2.4.18 的新手。
我有以下形式的网址,我想重定向。
Current URL: https://www.example.org/page/10/
Desired URL: https://www.example.org/index.php/page/10/
如果我使用以下规则,我可以修改请求,例如第 2 页:
Redirect permanent /page/2/ /index.php/page/2/
但是,我想重定向而不必对我网站上的所有页面进行硬编码。我尝试了以下方法,我的浏览器在多次重定向后失败:
RedirectMatch /page/(.*)/$ /index.php/page//
并且使用以下失败,我不知道为什么:
RedirectMatch "https://www.example.org/page/(.*)/$" "https://www.example.org/index.php/page//"
我做错了什么?
在你的行中
RedirectMatch /page/(.*)/$ /index.php/page//
/page/2/
实际上会重定向到 /index.php/page/2/
,但是这个新的 URL 将 仍然 匹配您的 RedirectMatch
正则表达式并将产生另一个重定向。这就是为什么它会无休止地重定向,直到浏览器放弃(参见 example)。
我会尝试使用 RedirectMatch ^/page/(.*)/$ /index.php/page//
,因此当重定向时,/index.php/page/2/
将不再匹配 ^/page/(.*)/$
并且不会产生递归重定向。
事后想想,为什么不使用 RewriteRule
呢?它会为客户端保存一个额外的 HTTP 请求,因为当您需要将客户端发送到不同的服务器时通常会使用重定向。
我是使用 Apache 2.4.18 的新手。
我有以下形式的网址,我想重定向。
Current URL: https://www.example.org/page/10/
Desired URL: https://www.example.org/index.php/page/10/
如果我使用以下规则,我可以修改请求,例如第 2 页:
Redirect permanent /page/2/ /index.php/page/2/
但是,我想重定向而不必对我网站上的所有页面进行硬编码。我尝试了以下方法,我的浏览器在多次重定向后失败:
RedirectMatch /page/(.*)/$ /index.php/page//
并且使用以下失败,我不知道为什么:
RedirectMatch "https://www.example.org/page/(.*)/$" "https://www.example.org/index.php/page//"
我做错了什么?
在你的行中
RedirectMatch /page/(.*)/$ /index.php/page//
/page/2/
实际上会重定向到 /index.php/page/2/
,但是这个新的 URL 将 仍然 匹配您的 RedirectMatch
正则表达式并将产生另一个重定向。这就是为什么它会无休止地重定向,直到浏览器放弃(参见 example)。
我会尝试使用 RedirectMatch ^/page/(.*)/$ /index.php/page//
,因此当重定向时,/index.php/page/2/
将不再匹配 ^/page/(.*)/$
并且不会产生递归重定向。
事后想想,为什么不使用 RewriteRule
呢?它会为客户端保存一个额外的 HTTP 请求,因为当您需要将客户端发送到不同的服务器时通常会使用重定向。