当您访问url中的文件夹时,在ajax站点上使用mod_rewrite加载根索引页



我正在构建一个Ajax站点,该站点运行根级index.html文件,并使用history.js的pushState/popState,我已经更新了url,使它们干净美观,没有散列或刘海(示例:site.com/section/1)。

我如何做一个mod_rewrite,以便当用户试图链接到site.com/section/1或site.com/section(或任何地方以外的根),服务器提供site.com/index.html?

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.html   [L]

如果你想对实际的请求(/section/1部分)做一些事情,你可以通过$1访问它。例子:

RewriteRule (.*) /index.html?path=$1   [L]

将/section/1重写为/index.html?路径=/部分/1

最新更新