简体   繁体   English

如何从共享主机上的 Laravel 9 网站 URL 中删除尾随的子文件夹/public/index.php?

[英]How to remove trailing subfolder/public/index.php from the Laravel 9 website URL on shared hosting?

I'm using Godaddy's shared hosting and the domain I'm using is the primary domain of the cPanel account, hence, I cannot change the document root for the Laravel site.我使用的是 Godaddy 的共享主机,我使用的域是 cPanel 帐户的主域,因此,我无法更改 Laravel 站点的文档根目录。 With the current .htaccess codes deployed, the homepage website URL shows up as - https://www.example.com/subfolder/public/index.php instead of https://www.example.com How do I remove the trailing /subfolder/public/index.php from the website?使用当前部署的 .htaccess 代码,主页网站 URL 显示为 - https://www.example.com/subfolder/public/index.php而不是https://www.example.8816897000我如何删除尾随 /来自网站的子文件夹/public/index.php?

I'm using the following .htaccess code in public_html to redirect traffic to the subfolder:我在 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>

And, this is the .htaccess code (also contains force HTTPS and www) inside subfolder/public:并且,这是子文件夹/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]

I've tried multiple variations of .htaccess found across multiple websites, but it hasn't resolved the issue.我尝试了在多个网站上发现的 .htaccess 的多种变体,但都没有解决问题。

Folder structure >> home/user/public_html/subfolder/public/index.php文件夹结构 >> home/user/public_html/subfolder/public/index.php

Got the trailing issue resolved by updating the public_html .htaccess:-通过更新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>

The .htaccess inside the public folder is the default Laravel code:- 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>

I've removed the .htaccess inside the subfolder .我已经删除了子文件夹中的 .htaccess。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM