Home > OS >  Laravel 8.4 – Remove Public from URL
Laravel 8.4 – Remove Public from URL

Time:02-11

I am working on creating a website that converts text into speech. I am using the script from codecanyon which is Developed with PHP 7.4.x and Laravel 8.4.x . The issue I am facing is that I don't want to show /public URL as a permalink to access the website. Now, if I type mywebsite.com/pubic then the website is accessible otherwise if I write mywebsite.com then it only shows the files. I followed some of the previous queries posted on StackOverflow but got no results. The topic I followed is Laravel 5 – Remove Public from URL I tried even by renaming server.php , copying .htaccess and rewriting it. But those all resulted in a screen showing up errors or even blank. You can check at Text To Speech.

My .htaccess file 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]

# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Any help will be highly appreciated.

CodePudding user response:

The content of public folder should go to the public folder of your server (fe it's public_html on my server), and everything else should be stored in a different folder (fe laravel_mywebsite). Then you should go to public_html/index.php and change the folder paths based on where you put your Laravel app.

CodePudding user response:

If you want to only use .htacces, you just need to rewrite all requests from /public to /

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]

CodePudding user response:

To remove the /public from the URL you are not going to use the .htaccess file.

What you are going to do instead is set the /public folder as the serving directory for your Server.

If you use Apache, just go to your /etc/apache2/sites-available/000-default.conf file and change the DocumentRoot from {your base folder}/ (usually /var/www) {your base folder}/public

  • Related