2018-03-21 17:58

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


This question already has an answer here:

i have a url which looks like

i want to change it as

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dsgw3315 dsgw3315 3年前

    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 404"

    点赞 评论 复制链接分享