react-router redirect to index.html AND remove www from url in .htaccess

后端 未结 1 1528
野趣味
野趣味 2021-01-24 06:11

I\'m building a small app in ReactJS, so all pages need to serve index.html and the JS handles the url. This works fine. But I\'d also like to have .htaccess remove www from the

相关标签:
1条回答
  • 2021-01-24 06:51

    Answered my own question

    <IfModule mod_rewrite.c>
      RewriteEngine On
    
      # remove www
      RewriteCond %{HTTPS} off
      RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
      RewriteRule ^(.*)$ http://%1/$1 [R=301,L,NE] 
    
      # redirect all to index
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ index.html [L,NC]
    </IfModule>
    
    0 讨论(0)
提交回复
热议问题