Enhance Your Website with Apache Redirects

Discover Frequently Used Apache Redirect Configurations

apache logo

Redirect from HTTP to HTTPS

RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
apache logo

Redirect from HTTP WWW to HTTPS without WWW

RewriteCond %{HTTP_HOST} ^www.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
apache logo

Redirect from HTTP without WWW to HTTPS with WWW

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [R=301,L]
apache logo

Redirect from a site with WWW to URL without WWW

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
apache logo

Redirect without WWW to URL with WWW

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
apache logo

Redirect from pages with slash to URL without slash

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=301,NE,L]
apache logo

Redirect from no slash URL to URL with slash

RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
apache logo

Redirect from multiple slash URLs to one

RewriteCond %{THE_REQUEST} //
RewriteRule ^.*$ $0 [R=301,L,NE]
apache logo

Redirect from one page to another page

Redirect 301 /old.php http://www.domain.com/new.php
apache logo

Redirect all pages in one folder to another folder (redirect folder)

RewriteBase /
RewriteRule ^main-folder/old-folder/(.*)$ /main-folder/new-folder/$1 [L,R=301]
apache logo

Redirect from one domain to another domain

RewriteCond %{HTTP_HOST} domain1.com
RewriteRule (.*) http://domain2.com/$1 [R=301,L]
apache logo

Redirect from a subdomain to the main domain

RewriteCond %{HTTP_HOST} ^teste\.redirectinfo\.com  [NC]
RewriteRule ^(.*) https://www.redirectinfo.com/$1 [L,R=301]
apache logo

Redirect pages from .html to pages without .html

RewriteCond %{REQUEST_URI} ! \.html$
RewriteCond %{REQUEST_URI} ! /$
RewriteRule ^(.*)$ $1.html
apache logo

Redirect pages without .html to pages with .html

RewriteRule (.+)/$ /$1.html [L,R=301]
apache logo

Redirect pages from index.php to slash

RewriteRule ^index.php$ / [QSA,R]
apache logo

Redirect pages from index.html to slash

RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]
apache logo

Redirect pages from index.aspx to slash

RewriteRule ^index.aspx$ / [QSA,R=301]
apache logo

Redirect pages from upper case to lower case

RewriteBase / 
RewriteCond %{REQUEST_URI} ^[^A-Z]*[A-Z].*
RewriteRule ^ ${lc:%{REQUEST_URI}} [L,R=301]
apache logo

Redirect pages from URLs with GET parameters to URLs without GET parameters

RewriteCond %{REQUEST_URI} /page.php
RewriteCond %{QUERY_STRING} ^id=1$
RewriteRule ^(.*)$ http://mysite.com/page/? [R=301,L]