Redirect 301 /pagename.php http://www.domain.com/pagename.html
Redirect 301 / http://www.domain.com/
Redirect 301 / http://www.domain.com/subfolder/
Redirect 301 /subfolder http://www.domain.com/
Example: If you want a .html extension to use the same filename but use the .php extension.
RedirectMatch 301 (.*)\.html$ http://www.domain.com$1.php
RewriteEngine on RewriteBase / RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc] RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/directory/index.html [R=301,NC] Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*) http://www.newdomain.com%{REQUEST_URI} [R=302,NC] Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/subdirname/(.*)$
RewriteRule ^(.*) http://www.katcode.com/%1 [R=302,NC] 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/
RewriteEngine on
RewriteCond %{QUERY_STRING} id=3
RewriteRule ^index\.php$ /path-to-new-location/? [L,R=301] 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/
RewriteEngine on
RewriteCond %{QUERY_STRING} id=3
RewriteRule ^sub-dir/index\.php$ /path-to-new-location/? [L,R=301] RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} 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] Example: The original URL being http://www.website.com/index.php?id=100 and the new page being http://www.website.com/100/
RewriteEngine On RewriteRule ^([^/d]+)/?$ index.php?id=$1 [QSA]
Example: The original URL is http://www.website.com/index.php?category=fish and the new page being http://www.website.com/category/fish/
RewriteEngine On RewriteRule ^/?category/([^/d]+)/?$ index.php?category=$1 [L,QSA]
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] RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [R=301,L] Example: Redirect blog.oldsite.com to www.newsite.com/blog/
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]
Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)/old-directory/(.*)$ $1/new-directory/$2 [R,L]
Debdut look after the technical side of the business, SEO strategy, consultancy, and building an interactive dashboard with Google data studio and Tableau. Outside work, he enjoys watching cricket and cooking over the weekend. Also, he loves coding with Python when he has time.