NGINX,尝试将一个URL重定向/重写直接到另一个URL,但忽略args包括“#”

时间:2019-01-15 16:48:45

标签: nginx

我正在尝试将一个URL重写/重定向到另一个URL,但是当它的参数中带有“#”时,它将拉入并显示在新URL中,例如。

https://blah.co.uk/ep/doc/index.jsp#/download 需要重写为 https://blah.co.uk/Download/?Mode=doc

现在,无论我怎么尝试,我总是得到重写的URL为 https://blah.co.uk/Download/?Mode=doc#/download

它似乎总是带通“#”及其后的所有内容。

1 个答案:

答案 0 :(得分:0)

这是因为根本没有从Web服务器请求哈希部分或URL(在您的情况下为<?php header('Content-Type: text/html; charset=utf-8'); if(isset($_POST['email'])) { $email_to = "myemail address here"; $email_subject = "Request from my Website"; $email_header = "my email address here"; $name = $_POST['name']; // required $company = $_POST['phone']; // required $email_from = $_POST['email']; // required $demowhat = $_POST['message']; // required $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Phone: ".clean_string($company)."\n"; $email_message .= "Email Address: ".clean_string($email_from)."\n"; $email_message .= "Message: ".clean_string($demowhat)."\n"; // create email headers $headers = 'From:'.$email_header."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> ),因此nginx从未看到过它,因此它不能成为URL重写的主题。您可以查看this question了解更多详细信息。 URL的哈希部分仅用于客户端处理,而摆脱它的唯一方法AFAIK是使用某些客户端JavaScript,例如:

#/download