简体   繁体   English

从 Lavarel App 中的 url 中删除 public/index.php

[英]Remove public/index.php from url in Lavarel App

Created my first Laravel App (Using Lavarel 7.x) on Ubuntu 18.04LTS with Apache2 on a local PC I have.在 Ubuntu 18.04LTS 上使用 Apache2 创建了我的第一个 Laravel 应用程序(使用 Lavarel 7.x)。

Followed setup intstruction from Lavarel Docs , all went well.按照Lavarel Docs的设置说明,一切顺利。
One issue is with the url: url 存在一个问题:

http://localhost/lavarel-project1/ - returns the directory listing

The apache2 virtual host file looks like this: apache2 虚拟主机文件如下所示:

<VirtualHost *:80>
   DocumentRoot /var/www/html/lavarel-project1/public

   <Directory /var/www/html/lavarel-project1/public>
       AllowOverride All
       Require all granted
   </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

From researching on the web - articles stated to copy server.php file from Lavarel App root directory and rename it index.php.通过对 web 的研究 - 文章指出从 Lavarel App 根目录复制 server.php 文件并将其重命名为 index.php。 This worked but then created routes in the app, found other issues with the url:这可行,但随后在应用程序中创建了路线,发现 url 的其他问题:

http://localhost/lavarel-project1/ - works
http://localhost/lavarel-project1/catlog/ - doesn't work
http://localhost/lavarel-project1/public/index.php/catlog - works

Here is the content of the .htaccess file in the public folder:以下是公共文件夹中 .htaccess 文件的内容:

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

  RewriteEngine On

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

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

  # Send Requests To Front Controller...
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [L]
</IfModule>

Researched this issue on the web - how to go about removing public/index.php from the url, but with little success - all methods recommended don't work, hence asking the question on here. Researched this issue on the web - how to go about removing public/index.php from the url, but with little success - all methods recommended don't work, hence asking the question on here.

thanks in advance.提前致谢。

I think you should not put '/public' at Directory tag.我认为您不应该将“/public”放在目录标签中。

Try this:尝试这个:

` <VirtualHost *:80> DocumentRoot /var/www/html/lavarel-project1/public ` <VirtualHost *:80> DocumentRoot /var/www/html/lavarel-project1/public

<Directory /var/www/html/lavarel-project1>
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
` `

This is my configuration and works fine.这是我的配置并且工作正常。

 <VirtualHost *:80>

 ServerName laravel.dev
 ServerAlias www.laravel.dev
 DocumentRoot /var/www/html/lavarel-project1/public
 
    <Directory /var/www/html/lavarel-project1/public/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        Require all granted
    </Directory>
 
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM