localhost 重定向到 https 并循环 url

Posted

技术标签:

【中文标题】localhost 重定向到 https 并循环 url【英文标题】:localhost redirect to https and loops the url 【发布时间】:2018-12-04 12:41:01 【问题描述】:

嗨,我在我的本地主机中配置了一个项目,但我遇到了这个问题,当我尝试输入这个 url localhost/project/public/ 它重定向到 HTTPS,另一个问题是它以这种方式重复 url https://localhost/project/public/project/public

这是我的 .htaccess 文件

选项 - 多视图

RewriteEngine On

# Ignore the Moodle Folder for the Laravel's Route System
RewriteCond $1 !^(cefovi)

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %REQUEST_FILENAME !-d
RewriteCond %REQUEST_FILENAME !-f
RewriteRule ^ index.php [L]

我不确定这个文件是问题还是我有其他错误配置。我有另一个项目应该具有相同的结构。

该项目在 public 文件夹中有一个调用 laravel 项目的索引文件和一个名为 cefovi 的 moodle 文件夹

我不太清楚是什么问题,希望你能帮忙,谢谢

我正在使用 Xampp,这是我的 httpd-vhosts 文件

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host.example.com
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host2.example.com
    ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
    ##ServerName dummy-host2.example.com
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>

【问题讨论】:

您能否也包括您的VirtualHost 配置?我认为 HTTPS 重定向正在那里发生。 【参考方案1】:

关于重定向到 HTTPS 可能是因为您的虚拟主机配置。请检查find a statement

SSLEngine 开启

在您的虚拟主机配置中并将其更改为

SSLEngine 关闭

另外,请查看this类似问题。

URL 重复很可能是由于 href 上使用的相对 url 如果你在 laravel 模板上,请使用这样的链接。

<a href="url('/posts')">link</a> 

而不是使用

<a href="/posts">link</a>

此外,您在标签上写的内容会影响您的引用/网址的处理方式。即,如果您的模板中有 &lt;base href="/project/public"&gt;,则所有其他相关引用都将在前面添加“/project/public”。

希望这会有所帮助。

【讨论】:

我不确定这是不是你要的文件

以上是关于localhost 重定向到 https 并循环 url的主要内容,如果未能解决你的问题,请参考以下文章

IIS Http 重定向

Microsoft Edge 将 http://localhost 重定向到 https://localhost

Tuckey 过滤器 - https 重定向

如何停止从 localhost 重定向到 https

wamp https vhost 域重定向到 localhost https

谷歌浏览器将 localhost 重定向到 https