【问题标题】:How can I catch all routes with apache and html如何使用 apache 和 html 捕获所有路由
【发布时间】:2018-06-15 22:59:30
【问题描述】:

我在 index.html 中编写了一个解析 URL 并重定向到正确目的地的 js 脚本。例如,它解析 example.com/#/info 并显示正确的链接。

我希望它处理任何 URL,例如 example.com/xyz。但它显示 404 错误。
当我像这样添加.htaccess 时:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^/#

# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /#/$1 [L,R=301]

但它不起作用。它会引发 too_many_redirects 错误。

【问题讨论】:

  • 哈希不发送到网络服务器——Apache,包括 PHP。

标签: javascript apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

仅使用 html 是无法做到的!您应该使用 php 或其他服务器端代码。您可以将文件重命名为 index.php 并设置这些重写规则和..

【讨论】:

    猜你喜欢
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 2021-08-13
    • 2015-12-31
    • 2017-01-12
    • 2020-12-03
    • 1970-01-01
    相关资源
    最近更新 更多