3

Stuck with this for a long time. I found similar questions but none of the answers are working for me! .htaccess in root folder looks like this:

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/public/ 
RewriteRule ^(.*)$ /public/$1 [L,QSA]
Shizzen83
  • 3,325
  • 3
  • 12
  • 32
Anant Mishra
  • 150
  • 1
  • 2
  • 10
  • 1
    Why don'[ you use the default Laravel htaccess file ?https://github.com/laravel/laravel/blob/master/public/.htaccess – Karl Hill May 14 '20 at 21:03
  • @KarlHill I tried the default file but still doesn't work! Do I have to change the htaccess file in the public folder too ? – Anant Mishra May 15 '20 at 19:14

4 Answers4

18

Create a file named as '.htaccess' in root and add the below code. That's it

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
Nabin Rawat
  • 347
  • 4
  • 8
0

The example here is in the /public directory. You will also need to configure you're server correctly and have it look only at the /public directory instead of root. You shouldn't need an .htaccess file in the root.

You will need a httpd-vhosts.conf with something like the following:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName yourapp.com
    ServiceAlias www.yourapp.com
    DocumentRoot /var/www/yourapp/public
</VirtualHost>

Notice this line:

DocumentRoot /var/www/yourapp/public

You can read more about Laravel webserver configuration here.

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
0

inside of your main .htaccess it should read:

<IfModule mod_rewrite.c>
   RewriteEngine on     
   RewriteCond %{REQUEST_URI} !^public
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

replace the existing " RewriteRule ^(.*)$ public/$1 [L] " if something like this exist.

Brennan James
  • 332
  • 2
  • 7
0

below solution worked for me.

Create .htaccess file in root directory and place code something like below. copy server.php file and paste it in root directory with named as index.php .

put below code in .htacess created file in root directory .

Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php