• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Michele Neylon :: Pensieri

Michele Neylon :: Pensieri

Technology, Marketing, Domains, Thoughts

mod_rewrite tricks

March 4, 2007 by Michele Neylon 3 Comments

Mod_rewrite is an incredibly powerful tool and a lot of us would be very lost without it!
 A couple of quick “tricks” using mod_rewrite – partially to help myself find them again in the future:

 Redirecting domain.tld to www.domain.tld

RewriteEngine On

RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.tld$ [NC]

RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]

 This can be put in a .htaccess in the website’s root.

It will match any HTTP request that is NOT for www.domain.tld and rewrite it to www.domain.tld

Changing File Extensions

If you have changed file extensions on a site, for example moving all files from being “.htm” to “.php” then this line of code will save you a lot of hassle.
Not only will it help with any inbound links, but also for any internal links that you need to edit, but haven’t:

 RewriteRule ^(.*).htm$ $1.php [R=301]

the first file extension in the line is the one you are replacing, while the second is the replacement.

Related Posts:

  • Video thumbnail for youtube video noazpa1x7ju
    Rutger Hauer's Monologue in Blade Runner
  • computer-code-screens
    Dodgy WordPress Developer Tactics
  • wine-prices
    Wine Is Confusing
  • Instafest-mneylon-2023
    Another Year of Listening to Music Visualised (sort of)
  • privacy-keyboard-keys
    My Privacy Has Been Sold
  • Hans Zimmer concert in Madrid 2023
    Another Year of Fun Concerts

Filed Under: apache, Techie :: Techno :: Tagged With: apache

Michele is founder and CEO of Irish hosting provider and domain name registrar Blacknight. Read More…

Reader Interactions

Comments

  1. steviewdr says

    March 4, 2007 at 7:34 pm

    AddHandler application/x-httpd-php .html .htm
    in a .htaccess file would be another idea.

  2. michele says

    March 4, 2007 at 7:35 pm

    You could do that, but why bother? 🙂

  3. Michele Neylon says

    September 28, 2007 at 1:41 pm

    Having said that .. I’ve had to actually do that on here since I moved over to MT so that I could keep using a particular 3rd party service!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

dotblog founder

Mastodon

Archives

  • Bluesky
  • Instagram
  • Threads
  • Twitter

Pages

  • About Me
  • About This Site
  • Archives
  • Comments Policy
  • Contact Me
  • Newsletter
  • Privacy

Blogroll

  • Blacknight Blog
  • Gordon Hudson
  • Stewart Curry
  • Paul Savage – BlackDog SEO
  • Grandad

Stalking Links

Subscribe to Michele Neylon :: Pensieri

Blogroll

  • Blacknight Blog
  • Damien Mulley
  • Gianni Ponzi
  • Gordon Hudson
  • Grandad
  • My Mastodon
  • Paul Savage – BlackDog SEO
  • Stewart Curry
  • Technology.ie Podcast
  • Tom Doyle

Sites

  • Business Travel Tips
  • Discount Coupon Codes
  • Domain News
  • Fat.ie – my diet blog
  • Film Posters
  • Film Reviews
  • Films
  • Free Desktop Wallpapers
  • Irish Blogger Discussion Forum
  • Irish Stamps
  • Movie Trailers and News
  • Paste.ie

Footer

Site hosted in Ireland by Blacknight - Content copyright Michele Neylon

Copyright © 2025 · Magazine Pro on Genesis Framework · WordPress · Log in