简体   繁体   中英

Laravel application on sub-directory

The laravel application seems to have routes issue with the sub-directory on server. With the running application on local machine does not work on temporary domain in sub-directory on live server. Playing around .htaccess seems to have different results.

This question is almost identical to what I would be looking for but he hasn't got any solution while I have got some work around.

The .htaccess within the laravel public have been modified to something like:

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

RewriteEngine On

RewriteBase /~timely/email-client  //<--base has been modified
# 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>

The application will redirect you to host gator 404 page .

Also I've added .htaccess to the main directory which will forward every request to public directory.

<IfModule mod_rewrite.c>
  RewriteEngine on 
  RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Upon removing the home/main .htaccess just works for / route: eg

http://gator4057.temp.domains/~timely/email-client/public will work but all other routes are redirected to the same host gator 404 page .

Your comments and answers will be appreciated.

Thanks

Step 1. Move all email-client/public to email-client/. Now we're getting somewhere. Warning: Don't forget to copy the .htaccess file too

Step 2 . Open email-client/index.php in your favorite editor and change

$app = require __DIR__.'/../bootstrap/app.php';

to

$app = require __DIR__.'/../email-client/bootstrap/app.php';
or may be
$app = require __DIR__.'/email-client/bootstrap/app.php';

and change:

require __DIR__.'/../bootstrap/autoload.php'

to

require __DIR__.'/../laravel/bootstrap/autoload.php'
or may be
require __DIR__.'/laravel/bootstrap/autoload.php'

Run command:

php artisan cache:clear  
php artisan config:clear
php artisan optimize

OR

If you dont wana to do more changes try this:

Put this in index.php file

$app->bind('path.public', function() {
    return __DIR__;
}

Hope work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM