laravel Apache 虚拟主机总是重定向到 /dashboard

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48513297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:18:50  来源:igfitidea点击:

Apache virtual host always redirecting to /dashboard

phplaravelapachexamppvirtualhost

提问by al.tron

I'm having what appears to be a common problem but any solutions I've found don't seem to work for my case.

我遇到了一个看似常见的问题,但我找到的任何解决方案似乎都不适用于我的情况。

I'm trying to set up a virtual host so that I can access the public file of my Laravel installation by going to "walkpeakdistrict.local" but when I type this address into google chrome I am always redirected to the xampp dashboard at this address "https://walkpeakdistrict.local/dashboard/".

我正在尝试设置一个虚拟主机,以便我可以通过转到“walkpeakdistrict.local”来访问我的 Laravel 安装的公共文件,但是当我在谷歌浏览器中输入这个地址时,我总是被重定向到这个地址的 xampp 仪表板“ https://walkpeakdistrict.local/dashboard/”。

I've installed Laravel in the following xampp directory: c:/xampp/htdocs/walkpeakdistrict_uk.

我已将 Laravel 安装在以下 xampp 目录中:c:/xampp/htdocs/walkpeakdistrict_uk。

I have "C:\xampp\apache\conf\extra\httpd-vhosts.conf" set up as follows:

我有“C:\xampp\apache\conf\extra\httpd-vhosts.conf”设置如下:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/walkpeakdistrict_uk/public"
    ServerName walkpeakdistrict.local
</VirtualHost>

And I have "C:\Windows\System32\drivers\etc\hosts" set up as follows:

我有“C:\Windows\System32\drivers\etc\hosts”设置如下:

127.0.0.1   localhost
127.0.0.1   walkpeakdistrict.local

If anyone could offer any insight into this issue I would be very grateful.

如果有人可以提供有关此问题的任何见解,我将不胜感激。

采纳答案by al.tron

Ok, I'm not sure why this was an issue but it seems to work when I change the virtual host's server name to anything other than ".local".

好的,我不确定为什么会出现这个问题,但是当我将虚拟主机的服务器名称更改为“.local”以外的任何名称时,它似乎可以工作。

Thanks again to all who replied!

再次感谢所有回复的人!

回答by al.tron

Put this as the first line in C:\...\httpd-vhosts.conf(and restart the web server):

将此作为第一行C:\...\httpd-vhosts.conf(并重新启动 Web 服务器):

NameVirtualHost *:80

So, it should look like this:

所以,它应该是这样的:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:/xampp/htdocs"
</VirtualHost>

<VirtualHost *:80>
    ServerName walkpeakdistrict.local
    DocumentRoot "C:/xampp/htdocs/walkpeakdistrict_uk/public"
</VirtualHost>

I would place all my projects somewhere outside of C:/xampp/htdocsand C:/xampp. Let C:/xampp/htdocsbe the standard localhost location, with just two files inside (simple index.phpand index.html), but use another one for the projects. Even better, use another partition, not the system partition C:. Like D:/projects, or so. So, you would have D:/projects/walkpeakdistrict_uk.

我会将我所有的项目放在C:/xampp/htdocs和之外的某个地方C:/xampp。让我们C:/xampp/htdocs成为标准的 localhost 位置,其中只有两个文件(简单index.phpindex.html),但为项目使用另一个文件。更好的是,使用另一个分区,而不是系统分区C:。像D:/projects,或者这样。所以,你会有D:/projects/walkpeakdistrict_uk.

Good luck.

祝你好运。

回答by smallflightlessbird

I'm pretty sure the issue for me had to do with SSL redirects, for some reason. When I edited my .htaccess to exclude local.mydomain.com when forcing https, I stopped getting redirected to the XAMPP dashboard.

由于某种原因,我很确定我的问题与 SSL 重定向有关。当我编辑我的 .htaccess 以在强制使用 https 时排除 local.mydomain.com 时,我不再被重定向到 XAMPP 仪表板。

Below is the section of my .htaccess that excludes local sites from redirecting to https. You can add extra RewriteCondlines for other local domains.

下面是我的 .htaccess 中排除本地站点重定向到 https 的部分。您可以RewriteCond为其他本地域添加额外的行。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !=localhost
    RewriteCond %{HTTP_HOST} !local\.
    RewriteCond %{HTTP_HOST} !other.localdomain.example.com
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/ [R,L]
</IfModule>

<IfModule mod_headers.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !local\.
    RewriteCond %{HTTP_HOST} !other.localdomain.example.com
    Header set Strict-Transport-Security "max-age=16070400" env=HTTPS
</IfModule>

回答by Aman Setia

Change your document root to this, just add a slash at the end of public and it will work

将您的文档根目录更改为此,只需在 public 末尾添加一个斜杠即可

DocumentRoot "C:/xampp/htdocs/walkpeakdistrict_uk/public/"

回答by Michael Amechi

I had this problem after developing my website and I got round it by simply rebooting my machine. Many months later, Google then invalidated the use of .dev so my virtual host stopped working. I changed the name of my virtual host to .test and got the dashboard. I had forgotten the simple solution and arrived on this page searching for a solution. Then i remembered......I rebooted my machine and hey presto....it worked. No more dashboard. I get the right homepage.

我在开发我的网站后遇到了这个问题,我通过简单地重新启动我的机器来解决它。几个月后,Google 使 .dev 的使用无效,因此我的虚拟主机停止工作。我将虚拟主机的名称更改为 .test 并获得了仪表板。我忘记了简单的解决方案并来到此页面寻找解决方案。然后我想起来了......我重新启动了我的机器,嘿,很快......它起作用了。没有更多的仪表板。我得到了正确的主页。