0

When i redirect a file using htaccess the images and css, javascript are not applied correctly.
for example, i've redirected the page,

http://example.com/  

to

http://example.com/au/

for this i've use the following code in htaccess,

RewriteRule ^([a-z]{2})/?$ index.php?cn=$1  

Now the pages are redirected correctly but not the css,images. what could be the issue? I've files like this,

/index.php
/style.css
/images/...
/.htaccess

Edit: <link rel="stylesheet" type="text/css" href="/style.css" />
1
  • Show how you link to css and images please (hrefs). That information is missing from your question. Commented Jul 22, 2011 at 11:51

2 Answers 2

1

Make sure that you don't have any absolute URL problems. When working with htaccess sometimes you may forget that the URL the browser thinks its visiting (a URL you've rewritten) doesn't necessarily directly correlate with the file hierarchy in your web root. I always recommend using absolute paths relative to the site's www root when dealing with external content. For example the proper link to load the style.css file would be:

<link type="text/css" rel="stylesheet" href="/style.css" />

And not...

<link type="text/css" rel="stylesheet" href="style.css" />

This way when the browser thinks it's in the au sub directory or even when its somewhere else, CSS, JavaScript, and image files can be loaded without having to specialize URL's based on the rewrite's URL.

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

1 Comment

Is this a live website we could visit. Some code or a live sample of the problem could help here.
0

You have to add a RewriteCond before the rule, to make sure that any files that actually exist (e.g. - style.css) don't get passed to index.php

Try adding this bit of code before your existing RewriteRule

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

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.