Skip to main content

Post categories

  • Drupal Tips & Tricks
  • Drupal Howtos
  • Drupal Themes
  • X Twitter
  • youtube
Home
Drupal 4U
Drupal Development, Drupal Web Design, Drupal SEO
  • Home
  • Showcases
  • Services
  • Blog
  • Themes
  • About
  • Contact

Breadcrumb

  1. Home
  2. Tips and Tricks
  3. 301 redirects for your Drupal website (.htaccess file)

301 redirects for your Drupal website (.htaccess file)

Tips and Tricks
January 25, 2015
Profile picture for user drupal
By drupal
  • facebook-f
  • twitter
  • envelope
  • print
413

Very often you will need to apply a 301 redirect to your Drupal website. You can do so by adding the following codes to your .htaccess file in the Drupal root directory. If you don't redirect either "non-www to www" or "www to non-www" search engines such as Google consider your www and non-www website as "duplicated content", what might be penalised. Another important case is the redirection of an old domain to a new domain. The code below, redirects not only the root domain, but all paths/files, what is absolutely key in most cases.

Generic redirect non-www to www in .htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Generic redirect non-www to www https in .htaccess

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

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

Generic redirect www to non-www in .htaccess

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

Generic redirect www to non-www https in .htaccess

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

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

Redirect an old domain to a new domain in .htaccess

Works for http and https, but SSL certificate has to be active, otherwise first error "site not secure"

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]

Redirect an old domain to one particular page in .htaccess

RewriteCond %{HTTP_HOST} ^(www\.)?name-of-domain\.net [NC]
RewriteRule ^(.*)$ http://www.name-der-domain.de/unterseite.html [R=301,L]

https://jweiland.net/know-how/internet/htaccess-konfigurieren.html#c2756

301 redirects for your Drupal website (.htaccess file)
Configuration

Read more articles

Newer
Use the Drupal module "Secure Site" to easily and quickly restrict the access to your website
Older
Use the Drupal module GeSHi Filter for syntax highlighting
  • Log in to post comments
Profile picture for user drupal
drupal
413
1
min read
A- A+
  • facebook-f
  • twitter
  • envelope
  • print

Contact Drupal 4U

Get in touch for questions and our Drupal development, design and SEO services.

Contact Us

We aim to reply the latest within 48h.

About Drupal 4U

We are a group of Drupal designers, developers and webmasters and we launched this website to share our experience and knowledge with you. Drupal is a free software package that allows you to easily organize, manage and publish your content, with an endless variety of customization. Drupal is open source software maintained and developed by a very large community of developers and users.

  • X Twitter
  • youtube

Drupal Services

  • Drupal Web Design
  • Drupal Development
  • Drupal SEO
  • Drupal Migration

Drupal 4U

  • Services
  • Showcases
  • Themes
  • Blog
  • About

Drupal Links

  • Official Drupal Website
  • Drupal Answers
  • More Than Themes
  • Theme Forest
  • DXPR: Drupal for Marketers
2012 - 2025, Drupal 4U

Footer menu

  • Contact
Home
Drupal 4U
Drupal Development, Drupal Web Design, Drupal SEO
  • Home
  • Showcases
  • Services
  • Blog
  • Themes
  • About
  • Contact
Clear keys input element