0

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. 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?

I'm using the following .htaccess code in public_html to redirect traffic to the subfolder:

<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:

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.

1 Answer 1

0

Folder structure >> home/user/public_html/subfolder/public/index.php

Got the trailing issue resolved by updating the 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:-

<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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.