How to redirect a website from a folder to the root folder?

How to redirect a website from a folder to the root folder? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the How to redirect a website from a folder to the root folder? error on your web browser. Problem :


I was running a website on a folder (www.example.com/folder).
The new version of the website is live and runs on the root folder.



How should I redirect users who visit the website using the old URLs (either because they bookmarked it or through search engines)?



And in the long term, can I 'clean' the search engines results by removing the old links that show up?


Solution :

If you use Apache you could use ModRewrite. Just put this in your .htaccess file in your root directory:



RewriteEngine On
RewriteRule ^/?folder/(.*)$ $1 [NE,R]


You can use a 301 redirect in your htaccess which is the most appropriate to denote that something has moved (mostly search engine wise).



Just put a line like this in the drupal .htaccess or even create a separate .htaccess in the folder you user (if you still have it)



    redirect 301 /your_folder http://www.yourdomain.com/


What I usually do with drupal is have it in a subfolder and when I am ready to move it to the main domain I just create an .htaccess file in the root directory with rewriting and never move the actual files. I have found that this is more convenient especially when wanting to change the main domain content fast (say restore from a backup, without messing with existing files, create a new dir and change .htaccess to point to that).



my .htaccess looks like:



    Options -Indexes
Options +FollowSymLinks

RewriteEngine on

# Redirect all user to WWW
RewriteCond %HTTP_HOST !^www.
RewriteRule ^(.*)$ http://www.%HTTP_HOST/$1 [R=301,L]

# Serve Drupal 7 from sub directory in web root
RewriteRule ^$ my_folder/index.php [L]
RewriteCond %DOCUMENT_ROOT/my_folder%REQUEST_URI -f
RewriteRule .* my_folder/$0 [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule .* my_folder/index.php?q=$0 [QSA]

We hope that this article has helped you resolve the redirects, mod-rewrite, error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=