Redirect with 301 Redirect – SEO friendly

Redirect= to redirect an old web page to a new one, Google recommends a server-side redirect through the HTTP status code 301 (Moved Permanently).

With this redirection you inform the search engines that the page has been moved permanently. You also enter the URL of the new page. When the Google (& Co.) robot finds the redirect at the next crawl of the page, it uses the redirect to capture the new URL of the website or the respective subpage(s).

Recommended is only the permanent forwarding by 301 Redirect, because the ranking of the old page is taken over.

En Redirect can be initiated via HTML, PHP, JavaScript or on the server side. You can also create 301 redirects using PHP, but for shorter load times, forwarding via.htaccess file should be preferred.

I only describe the redirections via.htaccess file (Apache web server).

301 Redirect of the entire domain

If the complete domain of a website has changed, write the following into the.htaccess file. All individual web pages and subpages are then forwarded:
rewrite engine on
RewriteRule (.*) http://neue-domain.tld/$1[R=301,L]

301 Redirect of individual (sub)pages

If the URL of a single subpage has changed, this is forwarded in this way:
rewrite engine on
Redirect 301 /all-page.html http://domain.tld/neue-seite.html

The old subpage should be specified by relative path and the new one by absolute path.

For multiple redirects of subpages, you simply enter one redirect per line.
rewrite engine on
Redirect 301 /all-page.html http://domain.tld/neue-seite.html
Redirect 301 /all-page2.html http://domain.tld/neue-seite2.html

301 Redirect of the start page without subpages
rewrite engine on
Redirect 301 / http://neue-domain.tld/

If there is no file named index.html in the main directory, this redirection works like this:
rewrite engine on
Redirect 301 /index.html http://neue-domain.tld/

301 Redirect from www to non-www

Recently, the non-wwww version of a website is preferred, since the www is in principle a subdomain and the website should run on the main domain. For SEO, however, it is irrelevant whether the website can be accessed with or without www. You should only pay attention that the www points to the non-www version of the website (or vice versa).

This can be done in the.htaccess file as follows:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.(.+)$[NC] RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

301 Redirect from HTTP to HTTPS

When using HTTPS, each subpage must be accessible either via HTTP or HTTPS. Otherwise you risk duplicate content, which has a very negative effect on the search engine ranking. This can be ensured by permanent redirects – 301 redirects.

If you want to access all (sub)pages of a website via HTTPS, write the following into the.htaccess file (provided a valid SSL certificate is installed).

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