我尝试将Homestead
与我的Angular项目一起使用,当我在浏览器中按下刷新的URI(实际上不存在)时,RewriteRule不会捕获请求,也不会重定向到Angular的index.html
文件可以处理URI。
这是我的.htaccess
文件:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) index.html [NC,L]
如果在路线上刷新,我总是得到No input file specified.
消息。在主路径(www.example.test /)上,index.html文件加载良好。
这种情况下正确的.htaccess配置是什么?或者如果不是.htaccess是问题我在哪里可以检查其他设置?
试试这个
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
</IfModule>
我发现了这个问题。
我的家园用Nginx
http服务器运行,因此.htaccess文件被忽略。
所以我需要编辑/etc/nginx/sites-enabled/mydomain.test
文件下的配置文件,用这个更新:
location / {
try_files $uri $uri/ /index.php?$query_string;
// this is what I added:
if (!-e $request_filename){
rewrite ^(.*)$ /index.html break;
}
}
这解决了这个问题。