【问题标题】:How to redirect react app to non www with htaccess file?如何使用 htaccess 文件将反应应用程序重定向到非 www?
【发布时间】:2022-01-24 20:09:11
【问题描述】:
我有一个使用 apache 服务器的 react 应用程序。
这是我的 .htaccess 文件
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
我想将 www.domain.com 请求重定向到 domain.com,
无论如何,我如何使用 htaccess 将请求 www 重定向到非 www ?
谢谢!
【问题讨论】:
标签:
reactjs
apache
.htaccess
【解决方案1】:
你可以用这个:
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]