Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access website from a sub folder inside the root folder?

I am about to deploy a laravel project. I uploaded all the files and the website is working fine but the only problem is when i try to access my website i.e for example if i try to write mywebsitename.com in the url then public directory is shown which is because i have symblinked my laravel's public folder to the public_html folder. I don't have any idea about how to edit the .htaccess file in order to load the website with mywebsitename.com and not mywebsitename.com/public. My htacess files code is

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

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

my file directory structure is shown in this image

please help me

like image 492
Jeffrin Jose Avatar asked Dec 11 '19 01:12

Jeffrin Jose


People also ask

What is the root folder of a website?

More About Root Folders & Directories. The term web root folder may sometimes be used to describe the directory that holds all of the files that make up a website. The same concept applies here as on your local computer — the files and folders in this root folder contain the main web page files, such as HTML files,...

Where are files stored in the root directory?

In some operating systems, files can be stored in the root directory, like the C:/ drive in Windows, but some OSs don't support that. The term root directory is used in the VMS operating system to define where all the user's files are stored. What is the root directory of an SD card? The root folder is the lowest level directory on your SD card.

What is the root directory for my WordPress files?

The /html folder is the root directory for your WordPress files. You can access the root folder via SFTP, SSH, or the File Manager. Was this page helpful? Thanks for letting us know!

Do you need a document root for your website?

No problem- we’ve got you covered! Our VPS Hosting option takes the guesswork out of website hosting.) A domain’s document root, also known as the home folder, is the main folder that contains all of the files for either a domain or a subdomain. The document root for your main domain name is your public_html folder.


2 Answers

I am guessing it is an apache server. If yes;

  1. Ensure your domain mywebsitename.com points to the public_html
  2. Add a .htaccess file in your root directory(public_html) and paste this in
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^(.*)$ public/$1 [L]
    </IfModule>
like image 149
hazelcodes Avatar answered Sep 25 '22 10:09

hazelcodes


I found a solution to this question.

1.Copy all the laravel files inside the public_html folder including the .htaccess file and the index.php file which is suppose to be inside the public folder(keep both the files inside the public folder).

2.Then link your storage to the public folder using SSH, for that open your SSH enter id and password and change directory using "cd domains/yourdomainname.com/public_html" then give the php artisan command i.e "php artisan storage:link" (note:- after changing the directory you can give all the php artisan commands like migrate and config:cache or clear:cache as you wish.

3.Now after the all the necessary commands are given you can access your fully functional website including the image display function if you type yourdomainname.com/public on the URL but if you type just your domain name then all the laravel files will appear on the browser to avoid this and to to jump inside the public folder directly create one more .htaccess file outside the public folder but inside the
public_html folder the copy the below given code and then if you just your domain name on the URL then your website will be directly displayed

Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ public [L]
like image 29
Jeffrin Jose Avatar answered Sep 26 '22 10:09

Jeffrin Jose