Log in

View Full Version : mod_rewrite url's???



linkrus
11-17-2006, 11:40 PM
Hi,

I see allot of sites (even dynamicdrive) that dont have file extenstions in there url's, they only have a slash.

e.g. instead of www.somedomain.com/example.html they have www.somedomain.com/example/

How is this done??

ive looked into mod_rewrite's and redirects for .htaccess, etc, but nothing seems to be right.

Any help on the matter would be great!

Thanks

mwinter
11-18-2006, 12:08 AM
I see allot of sites (even dynamicdrive) that dont have file extenstions in there url's, they only have a slash.

There's a difference between having no "extension" and a path that ends with a slash. The latter is a canonical URL referring to a directory on the server[1]. That is,

  http://www.example.com/foo/

refers to a directory, foo, at www.example.com. What happens next is a bit of magic on the part of the server: there will usually be a directive in the configuration that tells the server to look for a certain file if a request identifies a directory, rather than some other resource. If that file can be found, it's served to the client.

On Apache servers, this directive is named DirectoryIndex, and the default value is index.html. So, given the URL above, the server would look for a file named index.html in the foo directory. It's essentially the same thing as requesting

  http://www.example.com/foo/index.html

directly, though if index.html doesn't exist, the server will respond in different ways to those two URLs.

Actually handling "extension-less" URLs is more complicated, and I've briefly described four methods (http://www.dynamicdrive.com/forums/showpost.php?p=57105&postcount=4) in two previous posts. The information in the second linked post starts about halfway though, after the quote:



Also, Mike, I would like to know more if its not too much trouble,


Mike


[1] That's not necessarily true, but it's the most common situation, and it'll do for this explanation.

linkrus
11-18-2006, 12:35 AM
On Apache servers, this directive is named DirectoryIndex, and the default value is index.html. So, given the URL above, the server would look for a file named index.html in the foo directory. It's essentially the same thing as requesting


Thanks for helping me out.

I already knew that index is the default for a directory but i thought there was more to it than creating a directory folder for every page??

The reason im interested is this is because i read that you can also use this kind of linking method to improve seo for dynamic url's
e.g. http://www.somedomain.com/index.php?page=example chould be linked to like http://www.somedomain.com/example/

This is suppose to help with search engines indexing links and ofcourse its easier to type in directly.

Again thanks for your help.

chovy
11-18-2006, 12:54 AM
if you know regular expressions, the documentation for it should help you.

mwinter
11-19-2006, 11:55 PM
I already knew that index is the default for a directory but i thought there was more to it than creating a directory folder for every page??

As I wrote in the cited thread, doing that is impractical, certainly for any reasonably large site. Even on a smaller one, it's far from ideal.



The reason im interested is this is because i read that you can also use this kind of linking method to improve seo for dynamic url's
e.g. http://www.somedomain.com/index.php?page=example chould be linked to like http://www.somedomain.com/example/

Well ideally one wouldn't create URLs like the former in the first place.



This is suppose to help with search engines indexing links

Search engines aren't fond of documents the use query string parameters, though they will index them (Google indexes DD, for example). I don't know where the line is, though - SEO doesn't interest me that much.



and ofcourse its easier to type in directly.

Quite, which is why URIs should be designed to be simple from the outset.

You could use mod_rewrite to perform an internal redirect, but it would be necessary to modify the server configuration at the main server or virtual host level. As far as I can see, distributed configuration files (.htaccess) are too limited in ability to be useful, here. That is to say that I can get it to work on my test server, but only by modifying http.conf.

Mike