2

basically what im trying to do it :

http://mydomain.com/1/1

to

http://mydomain.com/index.php?mid=1&mpid=1

and im using these codes in htaccess.

RewriteEngine on
RewriteRule ^([^/]+)/([^/]+) index.php?mid=$1&mpid=2 [NC]

it works fine but the problem is that css get messed,its not loading css and images. whats the solution ?

5 Answers 5

4

The problem is that your CSS is no longer relative to the root of your site.

Your index.php file is at /, but when you rewrite to /1/1, the client thinks you actually are at /1/1, and looks for the CSS file relative to that path, as it should.

What you need to do is reference your CSS at the root, /style/something.css or whatever it is. Just make sure you have / at the front of that path.

Sign up to request clarification or add additional context in comments.

4 Comments

@testtet, YELLING DOESN'T HELP. I assure you that this is the problem, unless you can provide more information which may help. If you could actually link to your site, I'd be happy to take a look.
smartytouch.com/reset.css points to the css file, so href="/reset.css" is what you will need
The same thing holds for images. Make sure you use an absolute path, as the relative path is broken by URL rewrite
@testtet, Looks like you got it working. FYI, you are still missing 3 files... jquery-1.4.2.min.js, jquery.marquee.js, and scripts.js. You can find this easily by firing up Fiddler (fiddler2.com/fiddler2) and loading your page.
3

Use the base element to set the base URL for all assets (CSS and images, etc). Here's the docs: https://developer.mozilla.org/en/HTML/Element/base

<base href="http://www.yourdomain.com/">

Also, your .htaccess may be redirecting the calls for your CSS and images. Change your .htaccess to this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/([^/]+) index.php?mid=$1&mpid=2 [NC]

... that will check to make sure the requested file (-f) and the requested directory (-d) don't exist before doing any redirects.

Comments

2

There can be two problems:

CSS and Images are not loading at all

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$
RewriteRule ^([^/]+)/([^/]+) index.php?mid=$1&mpid=2 [NC]

Or the images now have different path. Always put slash at the beginning of the path, it will help. Especially in CSS file, where the path is taken relative from CSS file, not actual url.

Comments

0

Prepend

RewriteCond %{REQUEST_FILENAME} !-f    # Existing File 

before your RewriteRule - it prevents existing files, like css files, from being rewritten.

Comments

-2

Maybe the sript sends the wrong Content-Type. CSS-Data requires Content-Type: text/css.

PHP:

header("Content-Type: text/css");

With a file extension like '.php' no browser will sniff it correct.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.