Hi all,
This is probably a silly question, but I can't get my head around it.
How is this done? See example here: http://www.netbar.se (Sorry, in Swedish, but language is not important, you don’t have to read it).
Each category in products are linked to a directory, such as http://www.netbar.se/produkter/calvados/alla/ and there the page is presented.
But I doubt they have duplicated the site content in every category. Rather I thought it was done with an index.php in the directory “calvados”, that had an include(); to a file in the root. And that was repeated for each category. Of course that approach works, but when the file is included all relative links (/js/script.js, css/page.css, <img src=images/image.gif /> etc) in the file that is being included will not work. I took a look at topics regarding include(), but didn't get any wiser.
I have looked at the code and they do use relative links, how do they achieve it (without having absolute paths)?
Thanks for any insight and help.
Using directories instead of .php?var=value
Moderator: General Moderators
Re: Using directories instead of .php?var=value
Well, you could include/require files using those functions and the following example;
...meaning that the included file can be the same everywhere, so to speak. This is just one example of many.
But the more common thing today is also mentioned as SEO, Search Engine Optimization, a way to create better looking URI's.
http://www.example.com/index.php?page=foo
...becomes...
http://www.example.com/page/foo/
...as an example. This can be done either by using script, but I think the most common way is to tweak the webserver, telling it to rewrite the URI's as they are passed through...
Code: Select all
<?php
echo $_SERVER['DOCUMENT_ROOT'].'/file_to_include_here.php';
?>But the more common thing today is also mentioned as SEO, Search Engine Optimization, a way to create better looking URI's.
http://www.example.com/index.php?page=foo
...becomes...
http://www.example.com/page/foo/
...as an example. This can be done either by using script, but I think the most common way is to tweak the webserver, telling it to rewrite the URI's as they are passed through...
Re: Using directories instead of .php?var=value
Thanks for the fast answer. I'll try it.
Indeed, I want it for "good looking" URIs, and happened to see it on the mentioned site. Hopefully I can duplicate it now.
Thanks
Lunken
Indeed, I want it for "good looking" URIs, and happened to see it on the mentioned site. Hopefully I can duplicate it now.
Thanks
Lunken
Re: Using directories instead of .php?var=value
It's not the easiest part to understand, but there are small tutorials on how to do it, and might be interesting.
For more indepth info of the way to do it in Apache, using mod_rewrite; http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
Misc. interesting reading; http://www.webmasterworld.com/forum92/6079.htm
There are alot of places discussing mod_rewrite, just search abit for it.
For more indepth info of the way to do it in Apache, using mod_rewrite; http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
Misc. interesting reading; http://www.webmasterworld.com/forum92/6079.htm
There are alot of places discussing mod_rewrite, just search abit for it.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Using directories instead of .php?var=value
Using Apache, you need to install mod_rewrite. Then put a .htaccess file like this in the directory:
Then in the index.php script look at the $_SERVER['PATH_INFO'] (or other variables) to determine the path.
Code: Select all
RewriteEngine on
RewriteRule !\.(php|htm|html|cgi|js|ico|gif|jpg|png|css)$ index.php(#10850)
Re: Using directories instead of .php?var=value
Thank you all,
You have pointed me in the right direction, I am trying out a few different (working) solutions!
Lunken
You have pointed me in the right direction, I am trying out a few different (working) solutions!
Lunken