告诉 Apache 始终服务 index.php,无论 URL 中有什么
Tell Apache to always serve index.php, no matter what is in the URL
我在 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 ex 中的实际 /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>
我在 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 ex 中的实际 /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>