2

I am new to hosting web apps online. I wanted to host an app in my subdomain eg departmennt1.example.com. I added the subdomain in cPanel. Located its directory in file manager. It happens that the subdmain is also a folder in the root directory. I upload the locally working site in the subdomain folder. After setting up my database on the .env folder. I also ensure that my public folder files were inside the subdomain folder. I ensure that the app and the autoload.php in index.php file in the subdomain folder is pointing correctly to the vendor and boostrap folder.

After that, I tried loading the subdomain address in the browser, but only the index page ie.

Route::get('/', function () {
    return view('welcome');
});

any other URL will return like login will show

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I tried it on another hosting company where the subdomain by default resides in the public_html directory and everything worked out fine.

How can I host at the first hosting company?

1
  • If you only have an index.html file in the directory does it display it? If not then there is something wrong with the way the subdomain is pointing to the document root
    – Steve
    Commented Jul 22, 2020 at 21:49

1 Answer 1

2

I was able to solve the whole problem by changing my .htaccess file from

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

to

<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>

I dont know what the code above does. I'll love it to get explation for the greater good of all

2
  • 1
    This code basically sends all "virtual URL" requests to index.php (the Laravel front-controller) for Laravel to then lookup the route and build the page. You must have had something similar when you tried this at the other host that worked, otherwise you would have had 404s for all but the home page as well. (Requesting the root directory would call index.php by default - so these directives are not required for the home page.) If you removed the AddHandler directive then you might find you are now running a different version of PHP.
    – MrWhite
    Commented Jul 22, 2020 at 17:18
  • The code was actually set automatically from the second host. I spotted the difference and tried to gave it a trial. And luckily it worked. Both the two hosting companies had diffrent directory for the subdomain file. The one i had problem with had it subdomain folder in the root directory, with the second had the subomain folder in public_html directory
    – Othman
    Commented Jul 22, 2020 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.