Loading a whole website

Htaccess redirect generator



This htaccess creator generates 301 redirect match patterns for an htaccess file. It is especially useful for creating redirects from pretty links to any other URL. A pretty link is a URL that does not end with a file extension such as .html or .asp. A CMS like WordPress creates pretty links by default. Apache does have a built-in redirect function ("Redirect 301 / /") but this function does not work for pretty links. This is why we created this tool that generates pattern matches for pretty URLs automatically. Of course you can also use this pattern generator for other types of functions, that require you to create a regex match pattern for pretty URLs.

When creating the htaccess file, make sure to start the file with "RewriteEngine On" as you can see in the example at the bottom of this page.

Why use this pattern match generator?

Let's say you have a website with incoming backlinks to example.com/page1/. However, you want to redirect this URL to a different URL - or to the homepage. This is important, both for real users and search engines. If a search engines comes across a dead link, you will forfeit all the incoming "link juice", which has a negative effect on your SEO. Dead links also creates a bad user experience.

If this URL were a regular .html page, it would be easy to fix this in .htaccess. You could use add the line below, which redirects the URL to the home page:

Redirect 301 /page-with-backlinks.html /

However, this will not work for pretty links, which is why you then need to create a redirectMatch. Creating a redirectMatch can be a bit daunting for people with little experience of regex patterns (Regular Expressions). This is why we made an htaccess creator that does it for you. Of course you can also use this pattern generator for other types of functions, that require you to create a regex match pattern for pretty URLs.

Purpose of the .htaccess file

The .htaccess file is a configuration file for Apache servers, that tells the server how incoming URL requests should be routed. It is basically an elegant way to create redirects, rewrites, block bots, create 404 errors etc.

Apache vs Nginx

.htaccess files only work for Apache servers. Apache is still the most dominant web server software, especially at the lower end of the hosting market, even though it is slowly being replaced by Nginx. Your .htaccess file will not work on Ngnx Almost all shared hosting companies - and managed VPS providers too - use Apache.

Redirect vs rewrite

A redirect means that the URL in your browser changes. A rewrite means that the URL does not change, but it will still show the content from the URL that is being referenced to. So basically, a redirect and a rewrite are the same thing, except that a redirect makes visitors aware that the content is served from a different URL.

.htaccess example file

Here is an example of a complete .htaccess file for a WordPress configuration:

# invoke rewrite engine
RewriteEngine On
RewriteBase /
#Redirect 400,401,403,404,500 to main website
ErrorDocument 400 http://example.com
ErrorDocument 401 http://example.com
ErrorDocument 403 http://example.com
ErrorDocument 404 http://example.com/404-not-found
ErrorDocument 500 http://example
RewriteRule ^index.html$ / [L,R=301]
redirectMatch 301 ^/www.example.com/page-with-backlinks/?$ /
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

"RewriteBase /" is actually not required, since the root directory is the default location.