I created a project based on laravel api and nuxt (pre-rendered), where the backend (api), inside root
is served via api.domain.com (subdomain) and nuxt front-end, inside a separate folder root/client/dist
, is served via domain.com (primary domain). I created the following .htaccess file at the root:
<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}]
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/client/dist/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /client/dist/$1
# Handle Front Controller...
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ client/dist/index.html [L]
//FOR API REQUESTS (LARAVEL)
RewriteCond %{HTTP:Host} ^(?:api\.domain\.com)?$
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*) public/$1 [NC,L,NS]
</IfModule>
The urls domain.com and api.domain.com work fine. However, when I access domain.com/products
, it redirects to domain.com/client/dist/products/
, resulting in 404 Not Found
error. However, when I access the same url from homepage, it renders correctly without any redirection.
Is there any way I can solve this? I tested it with nginx sites-enabled and it works fine.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi @sdriyaz712,
I believe your issue is with the following redirection rule
You should add
!^/products
as a condition to it as well.Regards, KFSys