[英]Remove index.php from URL of Laravel
我在 Linux Mint 中使用 Laravel 5.5.12。我正在使用 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/$1 [L]
</IfModule>
但這不起作用。
任何人都可以在這方面幫助我嗎?
將您更改的任何內容重置為默認值。
在您的 apache 虛擬主機配置中,確保您的 DocumentRoot 正確(類似於 /var/www/html/laravelproject/public)。
您不需要對公共文件夾中的 .htaccess 文件進行任何更改,因為這會處理重寫 url 以刪除 index.php。 但是,在某些環境中,我不得不添加
RewriteBase /laravelproject
到公用文件夾中的 .htaccess。
我在這里找到了答案:
https://ma.ttias.be/remove-index-php-from-the-url-in-laravel/
總而言之,我將以下內容添加到 .htaccess 文件中,直接位於現有 index.php 條目的下方:
RewriteRule ^index.php/(.+) /$1 [R=301,L]
Go 到httpd.conf
文件,搜索行DocumentRoot
並將其更改為您的index.php
所在的位置。 例如:
DocumentRoot "C:/xampp/htdocs/myappfolder/public"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.