16
Nov
To avoid duplicate content problem with search engines, you have to redirect all pages to one common URL.
This you can achieve using mod_rewrite of apache and .htaccess.
To redirect any URL starting with www.domain.tld to domain.tld, you have to add the following code to .htaccess file.
Do a 301 redirect for all http requests that are going to the wrong url.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ [NC]
RewriteRule ^(.*)$ http://domain.tld/$1 [R=301,L]
</IfModule>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ [NC]
RewriteRule ^(.*)$ http://domain.tld/$1 [R=301,L]
</IfModule>
or
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.tld$ [NC]
RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
</IfModule>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.tld$ [NC]
RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
</IfModule>
To redirect domain.tld to www.domain.tld -
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.tld$ [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [R=301,L]
</IfModule>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.tld$ [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [R=301,L]
</IfModule>
or
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.tld$ [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]
</IfModule>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.tld$ [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]
</IfModule>
Share or Bookmark This Post With :
One Comment
|
|
Posted On November 28th, 2009
Please note the Google PageRank goes up to 10 and the best alexa rating is 1. Short Url Redirect |
Leave a Reply
Subscribe to RSS Feeds
Follow me on Twitter
Add to Favourite
Sponsors
Recent Posts
- Roundcube – Free browser-based IMAP client
- mtop – MySQL terminal based query monitor
- Kohana – Swift, Secure, and Small PHP 5 Fram...
- FormMail – free form processing PHP script
- Xataface – The fastest way to build a front-...
- dotProject – the Open Source Project Managem...
- The jQuery Form Plugin
- DocVerse has officially been acquired by Google
- HDGraph – a free tool for Windows to draw mu...
- RandomClass jQuery Plugin
Most Popular
- Send emails using PHPMailer an...
- Firefox Addons Essential for S...
- Free SEO Tools From SEOMoz.org...
- URL Rewriting for PHP Web Appl...
- Multiple Instances of Tomcat w...
- Apache 2.x + Tomcat 4.x + Load...
- Pagination in JSP/Java
- PHP – Mysql Open Source ...
- java.lang.OutOfMemoryError: Ja...
- HOW TO Subversion+Apache on Fe...
Tags
add ons
Apache
Date
email
featured
Fedora
FireFox
google
google news
httpd
Image
Java
JavaScript
JavaScripts
Jsp
linux
mobile applications
Mobile Apps
mobile browser
Mod JK
mozilla
Mysql
Open Source
Outlook
pagination
Performance
PHP
plugins
POP3
popular
Postfix
project management
prototype
SEO
Servlet
Spamassassin
SSL
String
Subversion
themes
Tomcat
twitter
Unix
windows xp
WordPress




