I have a domain mydomain.com
and a nginx space to host my website. The URL address mydomain.com
is already in use and I don’t want to buy another domain, so I created a subdomain myapp.mydomain.com
. Then I created a laravel API app myapp
for testing purposes and uploaded the code into /mydomain_com/myapp
folder via a FTP client.
The problem now is I have to configure my .htaccess
accordingly so the the app can run correctly.
At the current state, the homepage route /
is working fine, but everything else is not working.
mydomain_commyapp.env:
...
APP_NAME=myapp
APP_ENV=local
APP_KEY=base64:U4v....
APP_DEBUG=false
APP_URL=https://myapp.mydomain.com
...
mydomain_commyapproutesweb.php
Route::get('/', function () {
return view('welcome');
});
Route::get('/aaa', function () {
return view('welcome');
});
mydomain_commyapproutesapi.php
Route::apiResource('os', OsController::class);
Now, when I go to https://myapp.mydomain.com
I get this:
However when I try to visit https://myapp.mydomain.com/aaa
and https://myapp.mydomain.com/api/os
, I get this error ↓
Can You pls tell me what’s the problem with my mydomain_commyapp.htaccess
↓ ? Why is the homepage only working?
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{HTTP_HOST} !^subdomain
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{HTTP_HOST} ^subdomain
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
2
Answers
Im using the htaccess which is already with the laravel and Im posting it below, it works fine with me
Also check if the mod_rewrite is enabled in your server, if you are using ubuntu and apache2 server enable the mod_rewrite using the command
Kindly refer : Enable mod_rewrite
Update the content of .htaccess file in the root folder with this. It should work.