I am working on wamp. the link to my site is : localhost/tshirtshop/
Before rewriting it is : localhost/tshirtshop/index.php?product=12
After rewriting it is : localhost/product-title-p12
Problem: Everything is working fine. but the problem is with Css files.
This file is not including.. when i saw the source code (Ctrl+U) the path is like this :
localhost/tshirtshop/product-title-p12/styles/tshirtshop.css
What i tried:
I tried this
<style>
<?php include 'styles/tshirtshop.css';
</style>
It works but not a solution for me. as there are some other images to be included also i.e logo which results as this path: localhost/tshirtshop/product-title/images/tshirtshop.png
It might be a very easy solution. But i am facing problem since one hour. i tried googling for similar problems but not found any. so please dont mind. and sorry for my english.
use absolute path like
<link rel="stylesheet" type="text/css" href="http://localhost/tshirtshop/styles/tshirtshop.css" />
CSS isn't included in PHP like a typical server script, it's linked via HTML rendered by the client's web browser.
So instead of this:
<style>
<?php include 'styles/tshirtshop.css';
</style>
Try this:
<link rel="stylesheet" type="text/css" href="/styles/tshirtshop.css">
Yes you should avoid using relative paths for css and js. Only full paths will do the trick for you if you use seo urls with Apache's mod_rewrite. So this:
<link rel="stylesheet" type="text/css" href="theme.css">
on page
http://www.mypage.com/seo-url
searches for a css file in:
http://www.mypage.com/seo-url/theme.css
that does not exist. While this:
http://www.mypage.com/theme.css
is what you want. So use right from the very start:
<link rel="stylesheet" type="text/css" href="http://www.mypage.com/theme.css">
and you are done. Same with js.
I Can't tell exactly what the issue is without looking at your .htaccess
file (If you could include that we can help you debug further). But I'd warrant a guess that it just has a RewriteRule
?
What you should include before your rewrite rule is something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Your rewrite rule here...
There are other options aswell. You could specify a <base>
in your HTML markup. - Read More
That would look like this:
<base href="http://www.example.com/">
Which would allow you to use relative paths like you are currently doing. Your other option would be to do as the other answers have stated, but who wants to go through all their code and re write all of that stuff again?