1

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

1 Answers1

0

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"

Cameron Hurd
  • 4,836
  • 1
  • 22
  • 31