How to remove ".html" from URL?

Discussion in 'Web Design and Development' started by HarryPot, Aug 30, 2012.

  1. HarryPot macrumors 6502a

    Joined:
    Sep 5, 2009
    #1
    I have two things I would like to change:

    1. When entering my page www.domain.com, the URL is displayed as I would like it to show: "www.domain.com".

    But whenever I return to my homepage, it adds "/index.html" to the end, so I have: www.domain.com/index.html

    2. Every other page shows, www.domain.com/products.html, or /contact.html, etc.

    I would like that the homepage never shows "/index.html", and that the rest of the pages don't show the ".html". How can I achieve this?

    Thanks.:)
     
  2. jtara macrumors 65816

    Joined:
    Mar 23, 2009
    #2
    You need to configure your server. Most/all web servers have the ability (often by installing or enabling a plugin) to re-write URLs.

    Nobody can give you specific advice, though, without knowing what server you are using.
     
  3. rocknblogger macrumors 68020

    rocknblogger

    Joined:
    Apr 2, 2011
    Location:
    New Jersey
    #3
    If you have an Apache server you can use a ".htaccess" file to redirect however you want. There are many tutorials on how to do this. Use Google to find them.
     
  4. Apple Key macrumors 6502a

    Apple Key

    Joined:
    Jan 4, 2012
    #4
    I believe all you need to do is change the links on your site. Instead of linking to "index.html" for the homepage, link to "/". Then for the rest of the pages on your site, put them inside of subfolders. Such that the url would be "www.domain.com/products/".
     
  5. 960design macrumors 68000

    Joined:
    Apr 17, 2012
    Location:
    Destin, FL
  6. HarryPot, Aug 30, 2012
    Last edited: Aug 30, 2012

    HarryPot thread starter macrumors 6502a

    Joined:
    Sep 5, 2009
    #6
    I see a folder named "aspnet_client".

    I did search Google and found something about .htaccess, but I have no idea how to do it. Is .htaccess a file format? How do I make one?

    -------------------------------

    OK, I created a".htaccess" and uploaded it to my server. In the same directory as index.html is.

    Inside the htaccess file I wrote:

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    # index.html to /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3, 9}\ /.*index\.html\ HTTP/
    RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
     
  7. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #7
    If you have access to the server configuration, setting the "DirectoryIndex" (for example, in Apache) directive tells the web server which filenames are considered directory indexes and will be loaded by default in a given path even if not specified. Should be set in global portion of config but can be added to .htaccess or virtual hosts.

    http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryindex

    Example:
    DirectoryIndex index.html index.htm index.php

    Points to clarify:

    1) Make sure all your links do not include any filename specified in the directive
    2) Directory native .htaccess files with URL redirection or URI re-writing are excellent suggestions but are intended to OVERRIDE the GLOBAL settings in the config file, so if you ensure all links are set right and set DirectoryIndex globally, that will solve the fundamental issue of the OP. It will not solve issues related to dynamic link creation of course so I don't dismiss such advice entirely.

    Knowing when to do what is key to avoiding conflicts in settings.

    Hope this helps.
     

Share This Page