开发者

How to organize your site, so that .htaccess works

开发者 https://www.devze.com 2023-01-19 18:34 出处:网络
I am building a Dynamic web site from scratch for the first time so I am new at this. I need to match this URL:

I am building a Dynamic web site from scratch for the first time so I am new at this.

I need to match this URL:

www.domain.org/world/2.html

with this:

www.domain.org/index.php?html=world&rss=2

For that purpose I am using this rewrite rule:

RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?html=$1&rss=$2 [L]

And this should be working, but it is not!

If I write:

RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?html=$1&rss=$2 [R]

the site redirects me to the right URL and everything is working properly.

However, when I change the modifier [R] to [L] again, I receive a very strange page. It is the same that I need, but the css file is not loaded. Consequently, the internal URL is not exactly the same with what I need. When I echo开发者_开发问答 the $_GET[html] and $_GET[rss] variables, then they are the correct ones too. Additionally, when I go from link www.domain.org/world/2.html to another link from the menu, its builds like this: www.domain.org/world/2.html/environment.html, instead of www.domain.org/environment.html

So, I guess that the problem is with the organization of my site. The .htacces is in one directory. The template and css file is in another directory and the .php files handling different pages are in different directories. But then again

www.domain.org/index.php?html=world&rss=2 

works perfectly!!! Probably the .htaccess leads me to some wrong directory, but I do not know how to fix it.

So I am really confused where is the problem?! Please, if somebody has a clue, I will be very grateful to hear it.

Thank you for your time and consideration.


However, when I change the modifier [R] to [L] again, I receive a very strange page. It is the same that I need, but the css file is not loaded.

I guess you use relative URIs to reference the stylesheet. Like this:

<link rel='stylesheet' href='../screen.css'>

Since the browser thinks it is in the directory /world/ it searches in the wrong directory.

Solution: Use absolute paths starting with an /:

<link rel='stylesheet' href='/screen.css'>
<a href='/about/'>About us</a>
0

精彩评论

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

关注公众号