【问题标题】:htaccess html5 history api - redirect to root folder works only without hash in routehtaccess html5 history api - 重定向到根文件夹仅适用于路由中没有哈希
【发布时间】:2020-01-17 13:17:46
【问题描述】:

我已经使用 Navigo 为 html5 history api 配置了我的 htaccess 文件,如下所示:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

</IfModule>

只要我使用这种模式,它就可以正常工作:

mydomain.com/myroute

但是 - 如果像这样向路由添加 hash

mydomain.com/myroute/ 

重定向到 index.html 工作正常,但未加载 css und javascript,因为 index 尝试从子文件夹“myroute/”加载样式表和脚本,而该子文件夹当然不存在。

谁能告诉我如何解决这个问题?

谢谢和最好的问候!

【问题讨论】:

    标签: .htaccess html5-history


    【解决方案1】:

    答案是:嵌入带有前导哈希的脚本:

    src="/style.css" 
    

    而不是

    src="style.css"
    

    有时很容易:)

    【讨论】:

      猜你喜欢
      • 2017-12-12
      • 1970-01-01
      • 2011-01-14
      • 2015-10-06
      • 2020-03-31
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 2015-07-09
      相关资源
      最近更新 更多