更改配置和.htaccess文件后,无法从url中删除public/index.php



我现在正在本地服务器上工作,并试图从http://localhost/example/public/index.php/在url中。我关注了网站上的内容:https://www.tutsmake.com/how-to-remove-public-from-url-in-laravel/并添加了配置文件laravelex.conf,内容如下:

<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example/public
<Directory /var/www/example>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

在我的项目中,uder是我的公用文件夹.htaccess文件,如下所示:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ public/$1 [L]
</IfModule> 

但当我试图打开http://localhost/laravel_project_folder/甚至http://localhost/laravel_project_folder/index.php/我得到了内部服务器错误

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Apache/2.4.29 (Ubuntu) Server at localhost Port 80

日志文件中的错误是

AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

注意:我还试图通过查看@stephen:的答案,以以下方式更改.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

更改如下文件结构:

├── project folder
│   ├── core
│   │   └── laravel files
│   ├── html
│   ├── css
│   └── index.php

将所有项目文件复制到核心文件夹,并将公用文件夹的内容复制到主文件夹。

则在index.php:中固定CCD_ 1和CCD_

require __DIR__.'/core/vendor/autoload.php';
$app = require_once __DIR__.'/core/bootstrap/app.php';

很抱歉第一次回复太晚。但我发现我最终得到了来自不同来源的答案。首先,我把我的项目文件按以下顺序排列:

├──.cpanel/
├── public_html/
├── .htaccess
├── index.php
├── web.config ...
├── public_ftp/
├── laravel_project_folder
│   ├── app
│   ├── bootstrap
│   ├── config ...
│   └── index.php

现在我在两个地方更改了文件内容。

  1. 更改了以下行中的index.php:

需要DIR。'//vendor/autoload.php’;和$app=require_onceDIR。'//bootstrap/app.php’;

需要DIR.//laravel_project_folder/vendor/autoload.php';和$app=require_onceDIR。'//laravel_project_folder/bootstrap

/app.php’;

  1. 也更改了.htaccess的内容

最新更新