从 Laravel 的 URL 中删除 index.php
Remove index.php from URL of Laravel
我在 Linux 中使用 Laravel 5.5.12 Mint.I 我在使用 LAMP 堆栈。我想从 URL 中删除 index.php
。我的 mod_rewrite
apache 模块已启用。
我的 .htaccess
文件位于 public
文件夹中,它包含以下代码。
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
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>
我将 Laravel 根文件夹中的 server.php 重命名为 index.php 并将 .htaccess 文件从 /public 目录复制到 Laravel 根文件夹.但它不起作用。
我将下面的代码放在 .htaccess
文件中
<IfModule mod_rewrite.c>
# Turn Off mod_dir Redirect For Existing Directories
DirectorySlash Off
# Rewrite For Public Folder
RewriteEngine on
RewriteRule ^(.*)$ public/ [L]
</IfModule>
但这不起作用。
谁能在这方面帮助我?
将您更改的所有内容重置为默认值。
在您的 apache 虚拟主机配置中,确保您的 DocumentRoot 正确(类似于 /var/www/html/laravelproject/public)。
您不需要对 public 文件夹中的 .htaccess 文件进行任何更改,因为这会重写 url 以删除 index.php。但是,在某些环境中,我不得不添加
RewriteBase /laravelproject
到 public 文件夹中的 .htaccess。
我在这里找到了答案:
https://ma.ttias.be/remove-index-php-from-the-url-in-laravel/
总而言之,我将以下内容添加到 .htaccess 文件中,就在现有 index.php 条目的正下方:
RewriteRule ^index.php/(.+) / [R=301,L]
转到 httpd.conf
文件,搜索行 DocumentRoot
并将其更改为您的 index.php
所在的位置。例如:
DocumentRoot "C:/xampp/htdocs/myappfolder/public"
我在 Linux 中使用 Laravel 5.5.12 Mint.I 我在使用 LAMP 堆栈。我想从 URL 中删除 index.php
。我的 mod_rewrite
apache 模块已启用。
我的 .htaccess
文件位于 public
文件夹中,它包含以下代码。
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
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>
我将 Laravel 根文件夹中的 server.php 重命名为 index.php 并将 .htaccess 文件从 /public 目录复制到 Laravel 根文件夹.但它不起作用。
我将下面的代码放在 .htaccess
文件中
<IfModule mod_rewrite.c>
# Turn Off mod_dir Redirect For Existing Directories
DirectorySlash Off
# Rewrite For Public Folder
RewriteEngine on
RewriteRule ^(.*)$ public/ [L]
</IfModule>
但这不起作用。
谁能在这方面帮助我?
将您更改的所有内容重置为默认值。
在您的 apache 虚拟主机配置中,确保您的 DocumentRoot 正确(类似于 /var/www/html/laravelproject/public)。
您不需要对 public 文件夹中的 .htaccess 文件进行任何更改,因为这会重写 url 以删除 index.php。但是,在某些环境中,我不得不添加
RewriteBase /laravelproject
到 public 文件夹中的 .htaccess。
我在这里找到了答案:
https://ma.ttias.be/remove-index-php-from-the-url-in-laravel/
总而言之,我将以下内容添加到 .htaccess 文件中,就在现有 index.php 条目的正下方:
RewriteRule ^index.php/(.+) / [R=301,L]
转到 httpd.conf
文件,搜索行 DocumentRoot
并将其更改为您的 index.php
所在的位置。例如:
DocumentRoot "C:/xampp/htdocs/myappfolder/public"