sja*_*rni 1 apache .htaccess mod-rewrite rewrite url-rewriting
我用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页面提供所有内容,而没有实际/index.php的 url ex /index.php/loginwill be just /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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1328 次 |
| 最近记录: |