dongsi7759 2018-03-21 17:58 采纳率: 100%
浏览 80
已采纳

没有加载.htaccess css文件的seo友好网址[重复]

This question already has an answer here:

i have a url which looks like

https://sparkle.000webhostapp.com/movie.php?id=16

i want to change it as

https://sparkle.000webhostapp.com/movie/16

i have created .htaccess file as

   Options -MultiViews
RewriteEngine On

# redirect "/movie.php?id=xxx" to "/movie/xxx"
RewriteCond %{THE_REQUEST} \s/movie\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /movie/%1? [R=301,L]

# internally rewrite "/movie/xxx" to "/movie.php?id=xxx"
RewriteRule ^movie/([0-9]+)$ /movie.php?id=$1 [L]

but the problem is the style file ,i.e.,css file is not loaded. no styles are defined in the link

</div>
  • 写回答

1条回答 默认 最新

  • dsgw3315 2018-03-21 18:14
    关注

    If your CSS is referenced like this: <link rel="stylesheet" href="homepage.css" />, it will be relative to the request's path!

    Initially, requests to /movie.php?id=123 would render a page whose css was assumed to be at /homepage.css.

    But, when you create that rewrite, the request is understood as /movie/123, and the css is assumed to be at /movie/homepage.css.

    To get around this problem, begin the reference to your CSS with a /, so that it's always in reference to the web root.

    The updated <link> tag should be <link rel="stylesheet" href="/homepage.css" />

    You can confirm this by checking your browser's error console and looking for something like "GET https://sparkle.000webhostapp.com/movie/homepage.css 404"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥15 pyqt信号槽连接写法
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。