Forum Moderators: phranque
I would like it to show as
mydomain.com/subdomain/page
I am on virtual hosting running Apache 1.3. I read some documentation about redirects and maps, as well as few posts on WM, however I am still not clear how to do this (perhaps information overload). If there is post that already answered this question please point me to it as I wasn’t able to find it.
Thanks
First and foremost: Mod_rewrite cannot "hide" or change your page names (URLs). It can only change the filenames that Apache associates with the page names you link to on your pages. It's an important distinction.
Your first step is to change all the links on your pages to point to extension-less pages. (I strongly suggest you make a back-up copy of your site before starting.) Now that your links all point to extensionless URLs, those are the URLs that people will see, and that search engines will ist and spider.
Now you need to tell your server to associate those URLs with the real filenames on your server, and those filenames do (and must in most cases) have file extensions (to support correct MIME-type handling).
You don't have to use mod_rewrite to do this. Just turn on Content-Negotiation by adding
Options +MultiViews -Indexes
Be aware, though, that this is a feature that is not without drawbacks. For example, you won't be able to use "directory indexes" on your site any more. I mean the use of Apache-generated directory-listings of all files in each directory of your site -- Most modern sites don't use them, except those that provide a lot of files for users to download directly from one or more directories.
There is also a measurable server performance impact, since you are now asking your server to find a file or directory that matches the request most closely.
You can use mod_rewrite to do this "manually" if you so desire. This also has a performance impact, but perhaps a bit less than content-negotiation. A simple non-all-inclusive example would be:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([^./]+)+)/?$ /$1.php [L]
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com]. Also, check out the content-negotiation documentation on the Apache site.
Jim
RewriteRule ^(([^./]+)+)/?$ $1.html [L]
Note that forward slash before $1.html is missing. With fwd slash infront of it I was getting 404 message. I am still not sure why is this – my best guess is that has to do with parsing, but I’ll still have to think and figure out why it was ‘mis-parsing’ (if that was the reason anyway).
Speaking of ‘extension-less’ links, I am under the impression that it might be beneficial to set up site/links in that manner – especially if in future I want to change how my site delivers content (currently it’s bunch of include.php files). Is this true? What are drawbacks (except additional load on server)?
I already disabled dir indexing prior to tackling this current issue, as I don’t want that feature.
I am still building the site so changing the links to “extension-less” will not be an issue – actually none of the real links are up, just few test links (I disallowed all robots, and there aren’t any links on the home page, so nothing should be spidered until I am ready to go live). I am finalizing organizational and structural aspects of the site and afterwards I’ll add content.
Thanks again.
RewriteRule ^([^/]+/)*([^./]+)/?$ /$2.html [L]
RewriteRule ^(([^/]+/)*[^./]+)/?$ /$1.html [L]
The leading slash on the substitution 'roots' it to the DocumentRoot of the domain. If your files are actually in a subdirectory below DocumentRoot, then you'd have to take this into account if using a leading "/".
Jim
Jim