gpt4 book ai didi

php - URL 重写 : css, js,图片未加载

转载 作者:IT王子 更新时间:2023-10-28 23:56:27 25 4
gpt4 key购买 nike

我遵循 .htaccess

的规则
Options +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]

RewriteRule ^detail/([0-9]+)/?$ detail.php?id=$1

它将 http://localhost/detail/123 URL 重定向到 http://localhost/detail.php?id=123。页面重定向成功,但问题是CSS、JS和图片没有加载,

CSS、js文件位于http://localhost/css/http://localhost/js/

一种解决方案是使用绝对路径(例如/CSS 或/js 而不仅仅是 CSS/、/js,但这似乎不是一个可靠的解决方案,因为我们必须全部更改它文件,

基于.htaccess规则的任何其他解决方案,它独立于编辑所有PHP文件并让我们使用“相对路径”?

最佳答案

one solution is that use absolute path (ex /css, or /js rather than just css/, /js but this is not looks a reliable solution since we've to change it on all files,

这是因为您的相对 URI 的基数已更改。原来,基数是/当页面为 /detail.php?id=123 , 并且浏览器用 / 正确填写相关链接根据。但是当浏览器转到像 /detail/123 这样的页面时基地突然变成了/detail/它会尝试将其附加到所有相对 URL 的前面,因此它们都不会加载。

您可以将链接设为绝对链接,或更改页面标题中的 URI 基础(在 <head> </head> 标签之间):

<base href="/">

关于php - URL 重写 : css, js,图片未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12883273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com