php 可能对相关链接进行了不同的解释

relative links being interpreted differently possibly by php

在我网站的 a 标签中,我将它们设置如下:

<a href="/home"></a>

这在我的 http 测试服务器上运行良好,但是当我将我的站点推送到我的 https 生产服务器时,它会导致 "this site can not be reached page"。我发现通过在末尾添加 / 来修改 a 标签,如下所示:

<a href="/home/"></a>

让它发挥作用。我认为这可能是由于 PHP 的方式或服务器正在解释我的相关链接。谁能告诉我为什么这些末尾没有 / 的链接可以在 http 而不是 https 上运行?还有什么方法可以修改这个服务器端,而不必通过并添加 / 到所有链接的末尾?

谢谢!

您可以尝试通过对 .htaccess 进行如下编辑来自动更正此问题:

#declared once at top of htaccess file.
RewriteEngine On    

#if is a directory
RewriteCond %{REQUEST_FILENAME} -d
#enforce a trailing slash to the directory given
RewriteRule ^(.*[^/])$ // [L,R=301]

这会起作用,但我不确定您的服务器设置中操作的顺序优先级;在允许您的帐户 .htaccess 使用 URI 之前,亚马逊系统可能会检查它是否是一个文件夹。

但是上面的意思是:

www.yoursite.com/index.php

www.yoursite.com/home

将被服务器处理为:

www.yoursite.com/index.php

www.yoursite.com/home/ 
 --> and so will load the default index file from this directory, not shown to browser 
  --> www.yoursite.com/home/index.php