Skip to content

Redirect Rule for .htaccess for headless site

We need to implement a redirection mechanism to direct customers from our Magento site to our headless site.

Our frontend is hosted on the headless storefront, while the backend remains on Magento. The requirement is to redirect customers who open the frontend URL to the storefront URL, with some exceptions.

Example Requirement: If a customer opens abc.com, they should be redirected to xyz.com. However, if a customer opens abc.com/checkout, they should remain on abc.com/checkout. Any other URI apart from the specified exceptions should redirect to the storefront URL. Please ensure that this logic is implemented accordingly.

We have added the code below at

secure.czar-projects.xyz/html/pub/.htaccess

# Exclude specific URLs from redirection 
RewriteCond %{REQUEST_URI} !^/checkout [NC] 
RewriteCond %{REQUEST_URI} !^/admin [NC]

# Redirect all other URLs 
RewriteRule ^(.*)$ https://www.czar-projects.xyz/$1 [R=301,L]

Expectation: if we open https://secure.czar-projects.xyz/admin it needs to be open https://secure.czar-projects.xyz/admin
But if we open https://secure.czar-projects.xyz/about it needs to redirect to https://www.czar-projects.xyz/about

Thanks.