-2

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.

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]
Machavity
  • 30,841
  • 27
  • 92
  • 100
Arbab Ali
  • 21
  • 2
  • 8
  • Either use `php artisan serve` or point your server's "DocumentRoot" to the public folder – brombeer Feb 10 '22 at 14:54
  • @brombeer Second option worked best. How can I change the DocumentRoot for the folder inside the subdmain to /public . I mean changing from myweb.com/tool to myweb.com/tool/public – Arbab Ali Feb 11 '22 at 11:59

3 Answers3

3

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) to {your base folder}/public

ThomasSquall
  • 644
  • 6
  • 21
  • That's a nice suggestion and it worked. But now I want to redirect mywebsite.com/tool to my website.com/tool/public. I mean I want to change the root of mywebsite.com/tool . any suggestion via cPanel – Arbab Ali Feb 11 '22 at 04:53
  • @ArbabAli if the answer worked may you mark it as the solution so that can help other people? Regarding your next question, you usually do not want to use subfolder to serve different applications as webservers cannot handle subfolders but only domains and subdomains. For this reason is strongly suggested to use a subdomain instead, something like tools.mywebsite.com, and through a virtualhost send the traffic to the tool/public folder – ThomasSquall Feb 11 '22 at 10:46
  • Why not. For now, I am looking for some other suggestions too. Regarding the query, I already created a subdomain and working on it. If you have checked the link, it is tools.impressim.com. Regarding the query, I asked above of changing the document path for mywebsite.com/tool to my website.com/tool/public. I contacted the hosting provider they did some changes in the .htaccess but still, it is not working as desired. While changing the path at subdomain level works ok. Any help, how can I do it? so that myweb.com/tool has document path to myweb.com/tool/public. – Arbab Ali Feb 11 '22 at 11:56
1

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.

Bulent
  • 3,307
  • 1
  • 14
  • 22
0

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]
Oussama
  • 595
  • 5
  • 16