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.
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.
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.
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.
I had the same problem I just figured out this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([style|css|js|javascript|images|img|fonts|swf]+)/(.+)\.([^.]+)$ public/$2/$3.$4 [L]
as long as all the files are in the directory or sub directory of: style, css, js, javascript, images, img, fonts or swf it will work
change public to what ever folder inside the root, $2 is a folder css, js ... etc $3 is the rest fo the path
精彩评论