Map Extract
Free tool

.htaccess generator for Apache websites

Tick the rules you need for a site on Apache hosting and get a commented .htaccess file: HTTPS everywhere, one version of the domain, permanent redirects for pages that moved, a 404 page, compression and browser caching.

Runs in your browser. Nothing you enter is uploaded.

Making the file

  1. Choose the core rules

    Force HTTPS, Block directory listing and Gzip (deflate) compression are ticked by default. If the site sits behind a CDN or proxy, tick that box so the HTTPS check reads the forwarded protocol.

  2. Pick www or non-www

    Leave as is, redirect everything to www, or redirect everything to the bare domain. Choose the version your Google Business Profile and printed materials already use.

  3. Set caching and trailing slashes

    Browser caching ranges from off to a year for images and a month for CSS and JavaScript. Trailing slash removal is optional and leaves real folders alone.

  4. Add a 404 page and redirects

    Enter the path of a custom 404 page, such as /404.html. Then list 301 redirects one per line: the old path, a space, then the new path or full address.

  5. Download and rename

    The file downloads as htaccess.txt, because many systems hide files that start with a dot. Upload it to the site's root folder and rename it to .htaccess.

Example: a joinery firm after a website redesign

Oakfield Joinery's (fictional) new site uses tidy folder addresses, so three old pages need permanent redirects to keep visitors and search rankings. The firm also wants the bare domain only and a custom 404 page. The file below is the first part of what the generator produces; the compression and caching sections follow it.

Each section is commented, so whoever looks after the site next can see what each rule is for.

Input
Force HTTPS: on    www: Redirect to non-www
Custom 404 page: /404.html
301 redirects:
/services.html /services/
/contact-us /contact/
/old-offer https://oakfieldjoinery.example/offers/
Result
# Stop Apache listing the files in folders that have no index page
Options -Indexes

# Custom 404 page
ErrorDocument 404 /404.html

<IfModule mod_rewrite.c>
  RewriteEngine On
  # Remove www
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

  # Force HTTPS
  RewriteCond %{HTTPS} off
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# Permanent (301) redirects
Redirect 301 /services.html /services/
Redirect 301 /contact-us /contact/
Redirect 301 /old-offer https://oakfieldjoinery.example/offers/

Mistakes the generator catches

InputMessage
404 page written without a leading slash, such as 404.htmlThe 404 page must be a path on your site starting with /
A redirect line with only one valueWrite the old path and the new address separated by a space

Questions people ask

Does my website use .htaccess?

Only if it runs on Apache, or a server that reads Apache-style files such as LiteSpeed, which covers much shared hosting and many WordPress hosts. Sites on Nginx, most website builders and platforms such as Shopify, Wix or Squarespace ignore .htaccess and handle redirects in their own settings instead.

Why use 301 redirects after a redesign?

A 301 tells browsers and search engines that a page has moved permanently. Visitors following old links, bookmarks or printed addresses land on the right page, and search engines transfer the old page's standing to the new one. Without redirects those links end in a 404 error.

Why does my site show too many redirects after uploading?

A redirect loop usually means two rules disagree, for example the file forces HTTPS while a CDN or the hosting panel forces HTTP, or the www setting clashes with a platform setting. Restore the backup, then try again with the behind a proxy option ticked or with the duplicate rule removed.

Where do I put the .htaccess file?

In the website's root folder, the one that holds the homepage file, often called public_html or htdocs on shared hosting. Upload htaccess.txt, then rename it to .htaccess in your hosting file manager or FTP program. If a file is already there, merge carefully instead of overwriting, especially on WordPress.

Where your data goes

The file is built on this page from your choices. Your redirects, paths and domain are not sent to Map Extract or anywhere else.

Checked against the tool on

Top