【发布时间】:2021-02-03 06:43:06
【问题描述】:
我现在正在本地服务器上工作,并试图从 url 中的 http://localhost/example/public/index.php/ 中删除“/public/index.php”。我已经关注了该站点的内容: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>
在我的项目中,公共文件夹下我有.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>
【问题讨论】:
-
为什么不使用
PHP artisan serve? -
因为在项目之间以及在实时服务器上切换时会出现问题。
-
到底是什么问题?
-
无法打开网址中没有“/public/index.php”链接的网站的任何页面
标签: laravel configuration apache2 php-7 laravel-5.8