我用Javascript写了一个前端SPA。它使用Ember的路由、假URL、身份验证和Ember几乎隐式处理的所有惊人的东西。
后端用PHP编写,页面由Apache服务器提供。
现在,如果请求被发送到根文件(又名索引),页面工作正常,一切都从这里处理。但是,如果我在localhost/login
重新加载页面,Apache试图找到一个名为login的文件,这自然不存在,因为一切都在Javascript中处理,我得到了众所周知的404 - The requested URL /login was not found on this server.
我如何告诉Apache始终服务index.php
,无论在URL中是什么?
它应该看起来像Laravel的默认.htaccess,它将始终通过/index.php
页面提供所有内容,而url中没有实际的/index.php
,例如/index.php/login
将只是/login
,但值得注意的是,如果文件存在,这将不会强制它通过/index.php
页面。
# Checks if the rewrite mod is on.
<IfModule mod_rewrite.c>
RewriteEngine On
# Force everything through the index.php file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>