Website or Web page redirection using a .htaccess file?
One of the common and popular way to redirect your visitors is to use an .htaccess redirect. Before a page is served to the browser the server checks first for an .htaccess file and the visitors will be redirected to the new page.301 redirect is the most efficient method for webpage redirection.Also this method is a Search Engine Friendly method for web page redirection.
Read:How to specify your own ErrorDocuments using .htaccess file?
Let us see how do we set different types of redirection by using .htaccess file.
The following is the generic syntax to do the redirection.
Redirect /dir1/file1.html http://abcd.com/dir2/newfile.html
1. Redirect the site from without www to with www
This is used to redirect all users who access the site without the www. prefix.For example if you want to redirect all requests which are pointing to http://abcd.com/ to http://www.abcd.com.
Add the following line to the .htaccess file
1 2 3 4 5 | # mod_rewrite in use
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^abcd.com [NC]
RewriteRule ^(.*)$ http://www.abcd.com/$1 [R=301,L] |
2. Redirect the site from with www to without www
This is used to redirect all users to access the site with the www. prefix.
This is another common requirement.For example if you want to redirect all requests which are pointing to http://www.abcd.com/ to http://abcd.com. This can be easily achieved by adding a few lines of code into the .htaccess file.Even You can make your webserver so that if someone requests http://www.abcd.com/, it does a 301 (permanent) redirect to http://abcd.com/
Add the following line to the .htaccess file
1 2 3 | RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.abcd\.com$ [NC]
RewriteRule ^(.*)$ http://abcd.com/$1 [L,R=301] |
3. Redirect index.html to a specific sub-folder
You can redirect your default index file to a different directory or file.
Add the following line to the .htaccess file
1 2 3 | # Redirect index.html to a newdirectory subfolder Redirect /index.html http://globinch.com/newdirectory/ |
4. Redirect the entire site to a different URL
Add the following line to the .htaccess file
1 2 3 | # Redirect your entire website to any other domain Redirect 301 / http://globinch.com/ |
5. DirectoryIndex to redirect to specific index page:
1 2 | # Specify Specific Index Page DirectoryIndex index.html |
6. Redirect to secure version of your domain
This allows the users to redirect to secure site (https://)
Add the following line to the .htaccess file
1 2 3 | RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.abcd.com/$1 [R,L] |
Related articles
- 7 steps to Speed up website loading – Website Optimization Tips -Part 1
- Speed up website -Compress CSS/JavaScript using GZIP/DEFLATE compression – Optimization Tips -Part 2
- Check website/ web page for css/script Gzip/ Deflate compression – Optimization Tips -Part 3
Sign up or join Globinch on Social Media
Stay Connected
Follow globinch
Popular Posts
- Search Engines for File Sharing Sites : Rapidshare Search, Megaupload and More 6 comment(s) | 16258 view(s)
- Turn your Windows 7 Computer Into a Personal Wi-Fi Hotspot 15 comment(s) | 16117 view(s)
- Google Translate Now supports Bengali, Gujarati, Kannada, Tamil and Telugu 2 comment(s) | 15714 view(s)
- Google Top Searches Today – Hot Google Search Words today 12 comment(s) | 11559 view(s)
- Best PDF OCR Tools to Convert Scanned images to Text / Word Documents 20 comment(s) | 10154 view(s)
- Globinch Search 0 comment(s) | 8402 view(s)
- Access Blocked sites, Unblock Restricted Websites 15 comment(s) | 7313 view(s)
- Free Online OCR Software to Convert Images Into Searchable PDF, Doc, HTML or Text 3 comment(s) | 7238 view(s)
- Password Revealer – How To Reveal- Show Password Behind Asterisks? 7 comment(s) | 7180 view(s)
- Play Angry Birds Game Free and Offline in Chrome Browser 1 comment(s) | 7049 view(s)
Recent Articles
- Best Free Tools to Enlarge Images without Losing Quality
- How to Track Your Gmail Email and Schedule Gmail Mail Free?
- Google Webmaster Unnatural Links Detected Warning & Penalty
- How to Use Trial Software Version Forever Without Expire
- How to Use Folder as Drive or Convert Folder to Drive?
- Add Buttons, Message Boxes and Text Highlights in WordPress Post
- Top 20 Free WordPress Social Share Plugins
- rel=”shortlink” Short URL Indicator and Its WordPress Support
- Pagination SEO Using rel=”next” and rel=”prev” Link Attributes
- Watch Live IPL 2012 Season 5 Online on Your Computer or Mobile










Pingback: How to Use Google goo.gl to Create Short URLs and tiny url | Globinch
Pingback: .htaccess Tutorial -A guide and .htaccess tricks and tips | Globinch
Pingback: Make Long Hyperlinks to Short: Best URL Shortening Services | Globinch
Pingback: Handle ?ftr=vidpgurl and ?replytocom URLs: Avoid Duplicate Content Penalty | Globinch