Laravel-如何在Windows Xampp中从Laravel删除index.php [英] Laravel - How to remove index.php from Laravel in windows xampp

查看:67
本文介绍了Laravel-如何在Windows Xampp中从Laravel删除index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我的路线除了根主页以外都无法正常工作,我正在寻找两天时间来找到解决此问题的方法,并且发现我应该更改.htaccess文件,但是解决方案无法解决我的情况,起初,URL localhost/quotes/public与我合作得很好,但有时我不确定此问题是什么原因

my routes not working except the root home page, I'm searching for two days to find a solution to this problem and what I found that I should change .htaccess file but solutions didn't fix any for my case, at first the url localhost/quotes/public was working well with me, but at some point I'm not sure what is it this issue showed up

我尝试过的事情:

  • 创建另一条路线,我确保没有路线仅在工作 返乡路线,除返乡外仍无法正常工作
  • 试图将XAMP上的OverrideMode从无"更改为全部",没有解决任何问题
  • 试图手动键入localhost/quotes/public/index.php BOOM一切 可以..
  • create another route and I made sure that no routes are working only home route, still not working except home
  • tried to change OverrideMode on my XAMP from None to All, didn't fix any
  • tried to type manually localhost/quotes/public/index.php BOOM everything works ..

我的htaccess文件:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

        RewriteEngine On

    # 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]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

正在研究:

  • Windows 10
  • XAMP
  • Laravel 5.2.35

推荐答案

问题是您的.htaccess正在将所有内容都重写到通常位于{host}/index.php的前控制器中.但是,在您的应用程序中,它位于{host}/quotes/public/index.php.

The problem is that your .htaccess is rewriting everything to the frontcontroller, which is normally located at {host}/index.php. In your application however it is located at {host}/quotes/public/index.php.

因此,您有2个选择:

1.虚拟主机
在您的XAMPP Apache中设置指向的虚拟主机. myapp.localhtdocs/quotes/public以下是如何实现此目的的示例:如何在XAMPP上创建虚拟主机. (不要忘记将主机添加到您的hosts文件中,并使其指向127.0.0.1上的本地Macine.)然后,您可以在myapp.local/whatever-route-you-define上访问您的应用程序.另外,您可以忘记XAMMP并安装为此预先配置的 homestead虚拟机.

1. virtual host
Set up a virtual host in your XAMPP Apache that points ie. myapp.local to htdocs/quotes/public Here is an example of how to achieve this: how to create virtual host on XAMPP. (Don't forget to add the host to your hosts file and have it point to your local macine on 127.0.0.1) You can then access your application on myapp.local/whatever-route-you-define. Alternatively you forget about XAMMP and install the homestead virtual machine, which comes preconfigured for this.

2.重写规则
更改您的重写规则,以代替index.php将所有请求重写为quotes/public/index.php.我不是htaccess专家,但我相信它应该像更改此命令一样简单:

2. rewrite rule
Change you rewrite rule to rewrite all requests to quotes/public/index.php in stead of index.php. I'm no htaccess expert, but I believe it should be as simple as changing this:

RewriteRule ^ index.php [L]

对此:

RewriteRule ^ quotes/public/index.php [L]

请注意,您仍然需要通过localhost/quotes/public/whatever-route-you-define访问应用程序,这不是理想的imo.您的开发版本应尽可能接近实时版本,如果您开始使用绝对路径和相对路径以及代码中的内容,那么早晚会变得一团糟.

Do note that you'll still need to access your application trough localhost/quotes/public/whatever-route-you-define which is not ideal imo. Your dev version should be as close to your live version as possible, and if you start working with absolute and relative paths and stuff in your code things will become a mess sooner rather then later.

我个人会去Homestead,我一直都在使用它,一旦您运行它,它就会很好用.

Personally I would go for Homestead, I use it all the time and it works great once you have it running.

顺便说一句,localhost/quotes/public/index.php现在为您工作的原因是因为RewriteCond %{REQUEST_FILENAME} !-f告诉Apache 将任何请求重写为实际存在的文件(否则您将无法访问诸如CSS之类的静态资产.

Btw, the reason why localhost/quotes/public/index.php is working for you right now is because RewriteCond %{REQUEST_FILENAME} !-f tells Apache not to rewrite any requests to files that actually exist (otherwise you wouldn't be able to access static assets like your css).

这篇关于Laravel-如何在Windows Xampp中从Laravel删除index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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