ibrahimtuna
ibrahimtuna

Reputation: 23

How to redirect react app to non www with htaccess file?

I have one of react app working with apache server. Here is my .htaccess file

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

and i want to redirect www.domain.com requests to domain.com, anyway how can i redirect requests www to non-www with htaccess ? Thanks!

Upvotes: 2

Views: 833

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

You can use this :

Options -MultiViews
RewriteEngine On
#www to non-www redirection
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule (.*) https://%1/$1 [NE,L,R=301]
#rewrite non-files to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

Upvotes: 1

Related Questions