react使用BrowserRouter打包后,刷新页面出现404

文档
https://gkedge.gitbooks.io/react-router-in-the-real/content/apache.html

nginx nginx.conf

server {
  listen 80 default_server;
  server_name /var/www/example.com;

  root /var/www/example.com;
  index index.html index.htm;      

  location ~* \.(?:manifest|appcache|html?|xml|json)$ {
    expires -1;
    # access_log logs/static.log; # I don't usually include a static log
  }

  location ~* \.(?:css|js)$ {
    try_files $uri =404;
    expires 1y;
    access_log off;
    add_header Cache-Control "public";
  }

  # Any route containing a file extension (e.g. /devicesfile.js)
  location ~ ^.+\..+$ {
    try_files $uri =404;
  }

  # Any route that doesn't have a file extension (e.g. /devices)
  location / {
    try_files $uri $uri/ /index.html;
  }
}

apache 修改httpd.conf

Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
如果出现上面的错误,找到 LoadModule rewrite_module 这行, 取消掉前面的注释
https://stackoverflow.com/questions/10144634/htaccess-invalid-command-rewriteengine-perhaps-misspelled-or-defined-by-a-m

<VirtualHost *:80>
  ServerName localhost
  DocumentRoot D:\\apache\\Apache24\\htdocs\\build

  <Directory "D:\\apache\\Apache24\\htdocs\\build">
    RewriteEngine on
    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    # Rewrite everything else to index.html to allow html5 state links
    RewriteRule ^ index.html [L]
  </Directory>
</VirtualHost>
posted @ 2018-10-21 22:31  Ajanuw  阅读(1821)  评论(0编辑  收藏  举报