我在index.html中编写了一个js脚本来解析URL并重定向到正确的目的地。例如,它解析 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
错误。
最佳答案
仅仅用html是不行的!你应该使用 php 或其他服务器端代码。您可以将文件重命名为index.php并设置这些重写规则和..
关于javascript - 如何使用 apache 和 html 捕获所有路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48125326/