Forum Moderators: phranque
all my pages are followed by the .html extension, so when someone types in mysite.com/page it says page does not exist, so i need my site to automatically add the .html so it returns as mysite.com/page.html
i figured i could do 301 redirects but having to do one for every page seems really excessive and time consuming. I'm sure theres a mod_rewrite or something that can automatically add the .html extension to all the urls people try to access on my site.
I hope i explained that well, if you have any questions or can help, let me know
It'll serve you well to grasp the concept of how regular expressions work, when you're just starting out, if you'll be using mod_rewrite. Simply put, when a user agent (browser) requests a certain "pattern of characters" for a URL on your site, regular expressions tell the server to deliver or send it to a URL with a different pattern of characters - the one you tell it to in a directive in .htaccess
Here are some threads to look through on regular expressions [google.com].
Also, there are a few basic tutorials in the forum library [webmasterworld.com] that you should find very helpful to get a grounding in the basics.
[edited by: Marcia at 2:25 pm (utc) on Jan. 10, 2009]
What you really need is a rewrite. With a rewrite, the browser asks for www.example.com/somefile and the server fetches the content from the file /somefile.html without revealing what the real name of that file actually is.
Does this system need to work only on the root, or does it need to work site-wide into subfolders?
In any case, it is just one or two lines of code to work for the whole lot.
What is the over-all goal here?
The solutions are different if the goal is to publish and use 'extensionless' URLs, versus simply trying to correct linking errors made by other sites' Webmasters or in forum posts, etc.
Jim
My urls look like [mysite.com...]
The problem is people will try to directly type the page into the address bar as [mysite.com...] , so it wont return my page as it needs the .html extension
All i want to do is redirect all the pages typed in to the correct page ( essentially just adding the .html to the end of the url)
and g1smd, as of now theres no subfolders as it's a small site but if theres a way to make it work in the future if i end up adding subfolders that'de be nice too
Also thanks for the links marcia
# if request filename plus ".html" exists as a file
RewriteCond %{REQUEST_FILENAME}.html -f
# externally redirect to add ".html" to URL-paths without any extension
RewriteRule ^(([^/]+/)*[^./]+)$ http://www.example.com/$1 [R=301,L]
Jim