Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

.htaccess file and pretty urls

  • 05-06-2011 06:59PM
    #1
    Registered Users, Registered Users 2 Posts: 99 ✭✭


    I'm currently altering a website and I was hoping to give it 'pretty urls' in order to make it better for SEO and because it looks nicer.

    The only change to the .htaccess file I wish to do is to simply remove the .html so that for example

    'www.website.ie/contactus.html' shows 'www.website.ie/contactus'.

    I've tried google to assist me but every bit of code I've put into my .htaccess file hasn't worked. Can anyone help?


Comments

  • Closed Accounts Posts: 20,759 ✭✭✭✭dlofnep


    Yugioh wrote: »
    I'm currently altering a website and I was hoping to give it 'pretty urls' in order to make it better for SEO and because it looks nicer.

    The only change to the .htaccess file I wish to do is to simply remove the .html so that for example

    'www.website.ie/contactus.html' shows 'www.website.ie/contactus'.

    I've tried google to assist me but every bit of code I've put into my .htaccess file hasn't worked. Can anyone help?

    http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

    For anything that is going to be complex, that's the way to go.


  • Closed Accounts Posts: 20,759 ✭✭✭✭dlofnep




  • Registered Users, Registered Users 2 Posts: 1,657 ✭✭✭komodosp


    Hilarious

    I would have always just put an "index.html" file inside the contactus/ directory but yeah using a mod_rewrite probably gives a lot better flexibility.


  • Registered Users, Registered Users 2 Posts: 342 ✭✭adm


    wouldnt bother. removing .html will not help seo. only things like ? and & in url might affect seo.


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭oeb


    Off the top of my head, this should do it. (Make sure to test it first, this is just off the top of my head, and I have not actually tested it here first)
    <IfModule mod_rewrite.c>
        RewriteEngine On
        
        
        RewriteBase /
        
    
        RewriteCond %{REQUEST_FILENAME} !-F
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule (.*)/$ /$1.html [L,NC]
    </IfModule>
    

    That should check to see if a folder exists, and if it does not, load up /<FOLDER-NAME>.html.

    Keep in mind that you will need to modify all your calls for images, javascripts and links to use absolute URLs rather than relative ones. (IE /css/style.css rather than css/style.css)


  • Advertisement
Advertisement