0

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: e.g

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

Basheer Kharoti
  • 4,202
  • 5
  • 24
  • 50
  • Sorry, do you want your laravel project run on ```http://gator4057.temp.domains/~timely/email-client/```, right? – Henry Bui Apr 27 '18 at 06:14
  • @HenryBui yup that's what I'm looking for – Basheer Kharoti Apr 27 '18 at 06:14
  • I think it couldn't because when you go to `http://gator4057.temp.domains/~timely/email-client/public`, host can understand must go to ~timely/email-client/public. But when you go to `http://gator4057.temp.domains/~timely/email-client/xxx`, your host don't understand. Did you try `http://gator4057.temp.domains/~timely/email-client/public/xxx` – Henry Bui Apr 27 '18 at 06:28
  • doesn't work either – Basheer Kharoti Apr 27 '18 at 06:29
  • Do you have laravel code in this dir? MyUser/public_html/[laravel code here] ? I mean on server inside public_html – Jinandra Gupta Apr 27 '18 at 06:30
  • This question has been asked from seniors those who an idea. Please don't comment if you are beginner. – Basheer Kharoti Apr 27 '18 at 06:33
  • Hey I'm not beginner in laravel but yes of course here on stackoverflow. BTW you can move /public/index.php file along with other files to root directly but you have to do some changes in index.php also. Don't need to change anything in .htacces. – Jinandra Gupta Apr 27 '18 at 06:44
  • @JinandraGupta I can't move all of the code to `root` directory. There is already an application running on `public_html` – Basheer Kharoti Apr 27 '18 at 06:49
  • Ok, then create a sub-directory inside public_html/laravelcode/ and move public file inside /public_html/laravelcode/[ all public files here] – Jinandra Gupta Apr 27 '18 at 06:56
  • @JinandraGupta The application is within the `public_html` directory. e.g `public_html/email-client` – Basheer Kharoti Apr 27 '18 at 06:59

1 Answers1

0

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.

Jinandra Gupta
  • 546
  • 2
  • 9
  • Just take a look at this url. It works but all other `uris` are redirected back to `404` page. http://gator4057.temp.domains/~timely/email-client/public/ – Basheer Kharoti Apr 27 '18 at 07:21
  • I checked that If I manually type login page or registration page like http://gator4057.temp.domains/~timely/email-client/login , http://gator4057.temp.domains/~timely/email-client/register these both are also not working. – Jinandra Gupta Apr 27 '18 at 07:37
  • I've done some changes in my answer. Please try the below one in index.php file on top. Also replace RewriteBase /~timely/email-client by RewriteBase / in .htaccess file. – Jinandra Gupta Apr 27 '18 at 07:39