[英]How to remove trailing subfolder/public/index.php from the Laravel 9 website URL on shared hosting?
我使用的是 Godaddy 的共享主機,我使用的域是 cPanel 帳戶的主域,因此,我無法更改 Laravel 站點的文檔根目錄。 使用當前部署的 .htaccess 代碼,主頁網站 URL 顯示為 - https://www.example.com/subfolder/public/index.php而不是https://www.example.8816897000我如何刪除尾隨 /來自網站的子文件夾/public/index.php?
我在 public_html 中使用以下 .htaccess 代碼將流量重定向到子文件夾:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/subfolder/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ subfolder/public/$1
#RewriteRule ^ index.php [L]
RewriteRule ^(/)?$ subfolder/public/index.php [L]
</IfModule>
並且,這是子文件夾/public 中的 .htaccess 代碼(還包含 force HTTPS 和 www):
RewriteCond !{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
我嘗試了在多個網站上發現的 .htaccess 的多種變體,但都沒有解決問題。
文件夾結構 >> home/user/public_html/subfolder/public/index.php
通過更新public_html .htaccess 解決了尾隨問題:-
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond !{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !^/subfolder/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ subfolder/public/$1
#RewriteRule ^ index.php [L]
RewriteRule ^(/)?$ subfolder/public/index.php [L]
</IfModule>
public文件夾里面的.htaccess是默認的Laravel代碼:-
<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>
我已經刪除了子文件夾中的 .htaccess。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.