views:

46

answers:

3

I have .htacces like:

RewriteEngine On
RewriteRule ^en/$             index.php?page=index&lang_id=2
RewriteRule ^contact.html$    index.php?page=contact
RewriteRule ^en/contact.html$ index.php?page=contact&lang_id=2
# ...[and so on]

In my site i have a switch language button(image). My basic language is in Ro and and i want to swtich it into En. So, the point is that on a real server, the switcher works. On my local server, wamp, when I try to switch the language, in my browser it appears the text translated (as they are stocked in my database), but it doesn't recognized the css styles, images,...it appears only the text.

Where is the problem ? Please help me.

A: 

It is possible that you've some rule like RewriteRule ^en/(.*)$ index.php?page=$1.

For debugging, use the HttpFox extension for Firefox, and look which file is returned by the server, and if it's a 200 OK response.

Lekensteyn
+1  A: 

Are you using absolute or relative URLs for your external resources? The problem is probably that the extra folder pre-pended is breaking your relative urls.

So say you are using an image called logo.png and is hosted in an images folder, and is referred to with the image tag: <img src="images/logo.png" alt="logo" />. So normally, if you were on the contact.html page, the browser would check the location http://localhost/images/logo.png but with your /en folder, the browser will check http://localhost/en/logo.png which doesn't exist.

The way to fix this is using absolute urls, so using

<img src="http://localhost/images/logo.png" alt="logo" />

Should fix your issues.

Andrew Dunn
I have named my folders, images, css, with $BASE_URL just like in this example: "<link rel="stylesheet" type="text/css" href="{$BASE_URL}css/style.css">" and "<img src="{$BASE_URL}images/header.jpg" style="display: block">" and so on. BASE URL is defined to be the folder in wich i have all my site folders, subfolders etc. BASE URL is defined with Smarty, so can't figured why it doesn't work.
Danny
define("BASE_URL", "");
Danny
It looks like you need to set `BASE_URL` yourself, try setting it to `http://localhost/` otherwise it will simply output relative links again.
Andrew Dunn
A: 

Your browser propably makes a request for en/style.css, this gets redirected by the first rule to index.php?page=index&lang_id=2 in other words, it can never find the css that way.

Add

RewriteRule (css|jpg|png|gif|js|swf)$ - [L]

right after RewriteEngine On.

This makes sure that if the extention is one of the above, it doesnt redirect.

EDIT

alright say your relative link says css/style.css this gets automatically converted to baseURL + link since baseURL will be http://www.example.com/en/ it will look for the css in the folder en/css/style.css instead of css/style.css

one workaround would be to always get your css from your style folder, your images from your images folder, your javascript from your javascript folder etc.

example:

RewriteCond ([^/]+css)$ style/$1 [L]
RewriteCond ([^/]+(jpg|png|gif))$ images/$1 [L]
RewriteCond ([^/]+(js))$ javascript/$1 [L]
etc.
red-X
my style.css is in a folderd named css/style.css , I put youre code line in my htaccs but nothing happened. I think is a wamp problem, because as I already said, in my `virtual server` it doesn't work, on a real server it works.
Danny
changed answer.
red-X