Submit Your Article Forum Rules

Results 1 to 5 of 5

Thread: adding html extension

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    15

    adding html extension

    Is there a way in htaccess to catch url's coming in without the html extension and send them to the right page with the extension, right now if someone does not add that at the end of the address it returns a 404 for example
    /good returns 404 but
    /good.html returns the page.
    Basically I want to catch that and seamlessly send them to the right page.
    I have searched all over and can find a way to remove it but not add it.

  2. #2
    WebProWorld MVP chandrika's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    742

    Re: adding html extension

    I think it can be done in .htaccess using

    Code:
    <Directory /home/www/sitename/htdocs>
    Options + MultiViews
    </Directory>
    Content Negotiation - Apache HTTP Server

    However....apaches default setting in httpd.conf does not allow this, so unless you have root access to alter AllowOverride to include MultiViews in httpd.conf, that probably wont work.

    If you can see specific urls in the stats that are repeatedly lacking the extension, you could do redirects in htaccess for each specific url...depends how many urls it is happening to...if that is feasible its just

    Code:
    redirect 301 /good http://www.you.com/good.html

  3. #3
    WebProWorld MVP
    Join Date
    Aug 2003
    Posts
    1,039

    Re: adding html extension

    The following in your .htaccess should do the trick but you will want to test it fully before you go live with it:
    Code:
    RewriteCond %{REQUEST_URI} !^.*\.html$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ $1.html [L,R=302]
    Once you are happy change the R=302 in the last line to R=301, it's easier to work with temporary redirects while testing.

    The theory is that if the .html ending is not present and there is not a file or directory of the given name then it rewrites the URL to end .html.

  4. #4
    Junior Member
    Join Date
    May 2009
    Posts
    15

    Re: adding html extension

    Wonderful thanks speed that works perfectly, I was using lighty but just changed to apache so it is a new learning curve, its basically the same with slight differences, I worked out how to do redirects and custom 404 but could not work this one out, thanks all.

  5. #5
    WebProWorld MVP chandrika's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    742

    Re: adding html extension

    Yep thanks Speed, as I was also trying to do this, but got stuck with the way I was trying to do it.

Similar Threads

  1. Replies: 29
    Last Post: 09-08-2009, 01:27 AM
  2. html file w/ no file extension
    By kruser in forum Web Programming Discussion Forum
    Replies: 10
    Last Post: 02-16-2008, 12:04 AM
  3. HTML Validator is a Mozilla extension that adds HTML validat
    By dougadam in forum Graphics & Design Discussion Forum
    Replies: 3
    Last Post: 02-10-2007, 07:45 PM
  4. Adding cart functionality to existing html site
    By venividi in forum eCommerce Discussion Forum
    Replies: 1
    Last Post: 04-14-2006, 11:47 AM
  5. Adding encryption to HTML for privacy on forms?
    By Steve Landavazo in forum Internet Security Discussion Forum
    Replies: 4
    Last Post: 12-12-2004, 09:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •