By sdriyaz712
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.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @sdriyaz712,
I believe your issue is with the following redirection rule
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/client/dist/
You should add !^/products as a condition to it as well.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/client/dist/
RewriteCond %{REQUEST_URI} !^/products/
Regards, KFSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.