开发者

RewriteRule changes physical paths for files

Let's say the domain for my website is [http://mywebsite.com][1] and that opens the index.php. That script gets the $page,$section,$language variables from the url. So [http://mywebsite.com/index.php?lang=en&section=home&page=sitemap][2] opens the sitemap page in English which belongs to the "home" section. And I want that same url to be rewritten to [http://mywebsite.com/home/sitemap_en.html][3]. To achieve this, already I've put the following in the .htaccess: RewriteCond %{REQUEST_URI} .+\/.+ RewriteRule ^(.+)\/(.+)_(mk|en|al)\.html$ index.php?lang=$3&section=$1&page=$2 [L] But there is a huge problem now. When I visit some url like that, the files are not found because the file style.css is in the root folder and not in [http://mywebsite.com/home/style.css][4] , and there the server is searching for it. "home" is not real folder and it doesn't exists, it's only a section. The same goes for all the jpg, png, js, gif etc. How can I redirect the pages the way I like, and the files to be found with the real paths?

p.s. Some section like [http://mywebsite.com/index.php?lang=en&section=contact][5] don't have pages at all. They should b开发者_JAVA百科e reached like so: [http://mywebsite.com/contact_en.html][6] I have this for them, after the previous rule: RewriteRule ^(.+)_(mk|en|al).html$ index.php?lang=$2&section=$1


You can use a base tag in your header so that all relative paths are off of a specific href so:

<head>
    <base href="http://mywebsite.com/" />
</head>

would cause all relative (not just css) URL's to be loaded off your root directory

OR

as stated by others just make your paths absolute by putting a leading "/" at the front:

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


Did you try and make the references to css and js files etc relative to the top level directory (the home directory) by prefixing with a slash? ie if you keep them in a directory called styles in the sites home directory:

<link rel=StyleSheet href="/styles/style.css" type="text/css" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜