Drupal: How To Redirect When Site Moved From Subfolder To Server Root
When a site is under construction, it is often allocated in a subfolder of a working site. Search engines index it. And when the site is moved to root of a server, all indexed links break. This is not good. In addition, somebody could refer to the site while it’s being in a subfolder…
Solution:
Add the following code:
RewriteCond %{REQUEST_URI} ^/subfolder
RewriteRule ^subfolder(.*)$ http://site.ru$1 [R=301,L]
After these lines in .htaccess file (which is located in a site root):
<IfModule mod_rewrite.c>
RewriteEngine on
How it works:
- http://site.ru/folder → http://site.ru
- http://site.ru/folder/ → http://site.ru/
- http://site.ru/folder/* → http://site.ru/*
Advantages:
- Keeping of links value (with such redirect, search engines pass value to a new page)
- Old links still work