用webpack打包的前端代碼只有1個index.html實體文件,react-router控制路由。比如:localhost/index.htmlapache訪問的是入口文件:index.html.但是訪問localhost/list,路由由react-router控制,但是apache卻會查找項目目錄下的list.html文件。apache找不到該文件,報404錯誤。解決的方法,(我找到的是)開啟rewrite功能,并寫個.htaccess,讓所有404的頁面都rewrite到index.html主要步驟:1: 開啟apache rewrite功能:LoadModule rewrite_module libexec/apache2/mod_rewrite.so2: 配置apache conf:<Directory /> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride None Order deny,allow Allow from all AllowOverride All</Directory>3:在項目根目錄下寫個.htaccess文件:RewriteEngine OnRewriteBase /RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-lRewriteRule ^.*$ / [L,QSA]但是我在瀏覽器端輸入localhost/list依舊報404錯誤。求高手指點,是我找我了方法,還是方法細節(jié)有bug。thx。
關(guān)于webpack部署項目到apache服務(wù)器的url重寫
猛跑小豬
2018-10-17 17:14:24