首页 > 解决方案 > 在 .htaccess 中重定向时,& 符号被转义

问题描述

我希望 Apache 服务器将 URL 重定向https://frot.io/cvhttps://latexonline.cc/compile?git=https%3A%2F%2Fgithub.com%2Ffrot-io%2Fcurriculum-vitae&target=main.tex&command=xelatex,因此在 .htaccess 中插入了一个Redirect语句:

RewriteEngine On 
RewriteBase /

# Redirect to https
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

# Redirect frot.io/cv
Redirect 301 "/cv" "https://latexonline.cc/compile?git=https%3A%2F%2Fgithub.com%2Ffrot-io%2Fcurriculum-vitae&target=main.tex&command=xelatex"

但是,这会重定向到https://latexonline.cc/compile?git=https%3A%2F%2Fgithub.com%2Ffrot-io%2Fcurriculum-vitae%26target%3Dmain.tex%26command%3Dxelatex(两个与号和等号被转义),这会导致错误。

如何防止 apache 转义 URL 中的 & 符号?

我也试图逃避那些(%26%3D),但也被错误地重定向了。

标签: apache.htaccessredirectmod-rewrite

解决方案


我在支持人员的帮助下解决了这个问题:

RewriteEngine On
Redirect 301 /cv https://latexonline.cc/pending?git=https%3A%2F%2Fgithub.com%2Ffrot-io%2Fcurriculum-vitae&target=main.tex&command=xelatex
RewriteBase /
...

推荐阅读