Author: Bill Ross | Reading Time: 2 minutes | Published: March 4, 2026 | Updated: March 7, 2026 There are standard htaccess 301 redirect rules that I search for each time I build a website, redirect a page for an SEO strategy for a client, or help with a website’s SEO transition plan. So I thought I would create a resource to gather all the standard rules in one spot, saving me time on each project. The .htaccess file, short for Hypertext Access file, is a configuration file that manages a directory and its subdirectories on an Apache web server. If your website is hosted on a Linux-based plan, it probably runs on Apache. You might have noticed the .htaccess file in certain folders, especially if you’ve set up a site with WordPress, Shopify, Craft, or another content management system. The .htaccess file lets you give specific instructions to the web server, which is the program that delivers web pages to visitors. For example, you can use it to require a password for a folder, set up automatic redirects to another page or site, control access based on IP addresses, or hide directory listings. Example: If you want a .html extension to use the same filename but use the .php extension. Example: The original URL being http://www.website.com/index.php?id=3 and the new URL being http://www.website.com/path-to-new-location/ Example: The original URL being http://www.website.com/sub-dir/index.php?id=3 and the new page being http://www.website.com/path-to-new-location/ Example: The original URL being http://www.website.com/index.php?id=100 and the new page being http://www.website.com/100/ Example: The original URL is http://www.website.com/index.php?category=fish and the new page being http://www.website.com/category/fish/ Example: Redirect blog.oldsite.com to www.newsite.com/blog/ Common htaccess 301 Redirect Rules for SEO

What is an htaccess file?
Common 301 Redirect Htaccess Rules
Redirect a single page
Redirect 301 /pagename.php http://www.domain.com/pagename.html
Redirect an entire site or domain to a new one
Redirect 301 / http://www.domain.com/
Redirect an entire site to a subfolder
Redirect 301 / http://www.domain.com/subfolder/
Redirect a subfolder to a different website
Redirect 301 /subfolder http://www.domain.com/
Redirect a file extension but retain the page name
RedirectMatch 301 (.*)\.html$ http://www.domain.com$1.php
Redirect from an old domain to a new domain
RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Redirect from a non-www to a www subdomain
RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Redirect a domain to a www location with a subdirectory
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/directory/index.html [R=301,NC]
Redirect from an old domain to a new domain that includes the full path and query string
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*) http://www.newdomain.com%{REQUEST_URI} [R=302,NC]
Redirect from an old domain with a subdirectory to a new domain without the subdirectory but include the full path and query string
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/subdirname/(.*)$
RewriteRule ^(.*) http://www.katcode.com/%1 [R=302,NC]
Redirect URLs with query parameters with files placed in a root directory
RewriteEngine on
RewriteCond %{QUERY_STRING} id=3
RewriteRule ^index\.php$ /path-to-new-location/? [L,R=301]
Redirect URLs with query parameters and place files in a subdirectory
RewriteEngine on
RewriteCond %{QUERY_STRING} id=3
RewriteRule ^sub-dir/index\.php$ /path-to-new-location/? [L,R=301]
Redirect a site to HTTPS from HTTP to eliminate duplicate content
RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Redirect a site from HTTP to HTTPS to eliminate duplicate content
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
Remove an index.html or index.php and redirect to the root
RewriteEngine On
RewriteCond %{THE_REQUEST} /index.php HTTP [NC]
RewriteRule (.*)index.php$ /$1 [R=301,L]
RewriteEngine On
RewriteCond %{THE_REQUEST} /index.html HTTP [NC]
RewriteRule (.*)index.html$ /$1 [R=301,L]
Redirect URLs with query parameters to a directory-based structure while retaining the query string in the URL root level
RewriteEngine On
RewriteRule ^([^/d]+)/?$ index.php?id=$1 [QSA]
Rewrite URLs with a query parameter to a directory-based structure while retaining query string parameters in the URL subdirectory
RewriteEngine On
RewriteRule ^/?category/([^/d]+)/?$ index.php?category=$1 [L,QSA]
Redirect an old website to a new domain and retain the URL path
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example-old\.com$ [NC]
RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]
If you do not want to pass the path to the new domain, change the last line to:
RewriteRule ^(.*)$ http://www.example-new.com/ [R=301,L]
Add a trailing slash to URLs without one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [R=301,L]
Redirect from a blog subdomain to a blog folder
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI}/ blog
RewriteRule ^(.*) http://www.somewhere.com/%{REQUEST_URI} [R=302,NC]
RewriteRule ^(.*) http://www.somewhere.com/blog/%{REQUEST_URI} [R=302,NC]
Redirect one directory to another
Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)/old-directory/(.*)$ $1/new-directory/$2 [R,L]
- Our Story
- What We Do
Website Optimization
What's Your Situation
- What We’ve Done
- Resources
- Let’s Talk!