为什么我的网站 URL 末尾有双斜杠,如下所示:// [英] Why do I have double slashes at the end of my website URL like this: //

查看:115
本文介绍了为什么我的网站 URL 末尾有双斜杠,如下所示://的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我输入我的网站 zeugmarket.com 时,它显示为https://zeugmarket.com//

我写这个 htaccess 文件是为了从 HTTP 移动到 https,但它也在最后添加了两个斜杠.我如何阻止它:

RewriteEngine OnRewriteCond %{ENV:HTTPS} !on重写规则 ^(.*)$ https://www.zeugmarket.com%{REQUEST_URI} [L,R=301]标头始终设置 Content-Security-Policy upgrade-insecure-requests;";

解决方案

RewriteCond %{ENV:HTTPS} !on重写规则 ^(.*)$ https://www.zeugmarket.com%{REQUEST_URI} [L,R=301]

似乎还有别的东西";这是添加额外的斜杠 - 由于这些指令,它不会发生.

<块引用>

在我的网站 URL 的末尾像这样://

双斜杠实际上位于 URL 路径的开始,而不是严格的末尾.例如.如果您请求 http://example.com/foo,则它返回 https://example.com//foo.

然而,这个重定向响应实际上来自 Nginx 服务器,而不是 Apache.Nginx 可能被用作前端(反向)代理 - 因此要求使用 ENV:HTTPS(环​​境变量)而不是 HTTPS(服务器变量)RewriteCond 指令.

我会查找 Nginx 代理的配置问题,因为这很可能是添加了额外的斜杠.

<块引用>

RewriteRule ^(.*)$ https://www.zeugmarket.com%{$1} [L,R=301]

顺便说一下,在这个例子中(来自你的评论)%{$1} 不是严格有效的,并且总是会产生一个空字符串——所以双斜杠绝对不是来自 Apache.>

但是,您似乎有一个单页网站.您在任何 URL 上都没有任何 URL 路径?只有一个可见的 URL,那就是 https://www.example.com/,因此可以简化您的指令:

RewriteCond %{ENV:HTTPS} !on重写规则 ^ https://www.example.com/[L,R=301]

请注意,主机名后面应该有一个斜杠(在 URL 路径的开头).如果您省略它,那么(通常)浏览器 将在重定向的请求 中附加斜杠.(但似乎 Nginx 实际上在重定向响应中附加了这些斜杠 - 在它到达浏览器之前.)

有关浏览器和主机名后斜杠的更多信息,请参阅网站管理员堆栈上的以下问题:

https://webmasters.stackexchange.com/questions/35643/is-trailing-slash-automagically- added-on-click-of-home-page-url-in-browser

When I type my website zeugmarket.com it comes out as https://zeugmarket.com//

I wrote this htaccess file to move from HTTP to https but it is also adding two slashes at the end. How do I stop it:

RewriteEngine On
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://www.zeugmarket.com%{REQUEST_URI} [L,R=301]
Header always set Content-Security-Policy "upgrade-insecure-requests;"

解决方案

RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://www.zeugmarket.com%{REQUEST_URI} [L,R=301]

There would seem to be "something else" that is adding the additional slash - it's not happening because of these directives.

at the end of my website URL like this: //

The double slashes are actually at the start of the URL-path, not strictly at the end. eg. If you request http://example.com/foo then it returns https://example.com//foo.

However, this redirect response is actually coming from an Nginx server, not Apache. Nginx is probably being used as a front-end (reverse) proxy - hence the requirement to use ENV:HTTPS (environment variable) and not HTTPS (server variable) in the RewriteCond directive.

I would look for a config issue with the Nginx proxy, as it's most probably this that is adding the additional slash.

RewriteRule ^(.*)$ https://www.zeugmarket.com%{$1} [L,R=301]

Incidentally, in this example (from your comment) %{$1} is not strictly valid and will always result in an empty string - so the double slash is definitely not coming from Apache.

However, you appear to have a single-page-website. You do not have any URL-path on any URLs? There is only one visible URL, and that's https://www.example.com/, so your directives can be simplified:

RewriteCond %{ENV:HTTPS} !on
RewriteRule ^ https://www.example.com/ [L,R=301]

Note that there should be a slash after the hostname (at the start of the URL-path). If you omit it then (ordinarily) the browser will append the slash in the redirected request. (But it seems that Nginx is actually appending these slash(es) in the redirect response - before it gets to the browser.)

For a bit more information about the browser and the trailing slash after the hostname, see the following question on the Webmasters stack:

https://webmasters.stackexchange.com/questions/35643/is-trailing-slash-automagically-added-on-click-of-home-page-url-in-browser

这篇关于为什么我的网站 URL 末尾有双斜杠,如下所示://的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆