Home > database >  How to deploy laravel in subdirectory for windows server return 404
How to deploy laravel in subdirectory for windows server return 404

Time:09-29

I tried to deploy my laravel project in a subdirectory in windows server, but it's always returns 404 Not Found. Any ideas why this happens?

CodePudding user response:

Step 1:

Inside your project add or replace .htaccess file with above code:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

 RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    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

</IfModule>

Step 2:

Now in your project inside public folder add or replace .htaccess file with above 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]

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

Step 3:

After this you can directly call you project with subdirectory name

CodePudding user response:

Maybe you can create a .htaccess file in root that includes:

<IfModule mod_rewrite.c>
  <IfModule mod_negotiation.c>
    Options -MultiViews
  </IfModule>
  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
</IfModule>

EDITED: Another way is creation of a virtual host in apache. you can googling for how to. and there are so many tutorials for that. But you must be careful the destination uri must be /public folder.

  • Related