homepage Welcome to WebmasterWorld Guest from 54.145.183.190
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Mod Rewrite - Adding more Conditions
Mod Rewrite Conditions
mavi

5+ Year Member



 
Msg#: 3491779 posted 7:43 pm on Oct 30, 2007 (gmt 0)

Hi there
This is the first time i got a mod_rewrite work.
But unfortuneately there is a LIL Problem

I have 2 domains and want all the www and non-www versions to be redirected to www.domain2.com
The problem is that SE already indexed hundreds of pages and used all 4 variations.

300 times - domain1.com
940 times - www.domain1.com
100 times - domain2.com
2000 times - www.domain2.com ( thats the only one i want )

www.domain2.com is the most popular one and i cannot make DNS ( A ) modification becasue of my provider... so i have to do this with a mod rewrite.

This is what i did do redirect www.domain1.com to www.domain2.com
It works and gets rid of 940 bad crawls...
--------------------------------------------------
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain1.com$ [NC]
RewriteRule ^(.*)$ [domain2.com...] [R=301,L]
--------------------------------------------------

But i also wanna get rid of the non www domains, so i tried to add 2 more conditions.

I tried to add following in line 3
--------------------------------------------------
RewriteCond %{HTTP_HOST} ^domain1.com$ [NC]
RewriteCond %{HTTP_HOST} ^domain2.com$ [NC]
--------------------------------------------------

But nothing happens... After adding thos 2 lines, no redirection works.

Would be great if anybody could help me with this....

Thanx and best regards
MAVI

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3491779 posted 8:00 pm on Oct 30, 2007 (gmt 0)

You need to use the [OR] flag so that the rule is invoked for one RewriteCond OR the other. With a few corrections and a trick to make this more efficient, we get:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^domain2\.com [NC]
RewriteRule (.*) http://www.domain2.com/$1 [R=301,L]

This will 301 redirect domain1.com, www.domain1.com, or domain2.com to www.domain2.com

Jim

[edited by: jdMorgan at 8:40 pm (utc) on Oct. 30, 2007]

mavi

5+ Year Member



 
Msg#: 3491779 posted 10:34 pm on Oct 30, 2007 (gmt 0)

Hi Jim

1000 Thanx... and thanx for the answer to my robots post too..

I ve been trying this for weeks, ant it fianlly works.

Regards

Mavi

mavi

5+ Year Member



 
Msg#: 3491779 posted 11:01 am on Nov 2, 2007 (gmt 0)

... something else

Should I add a

Options +FollowSymlinks

after

rewriteengine on?


... I want SE to stop indexing the old domainnames.

Thanx

Mavi

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3491779 posted 12:41 pm on Nov 2, 2007 (gmt 0)

If your code works, then that indicates that the Options +FollowSymLinks setting has already been made in the server config file httpd.conf or conf.d. Therefore it is not necessary to repeat this directive.

The Options +FollowSymLinks setting has nothing to do with whether search engines will index the old domain names. If these domains are hosted in separate 'accounts' -- each with their own Web root (home page) directory, then you can add a robots.txt file to each Web root directory to stop SE indexing.

However, you may wish to consider using 301-Moved Permanently redirects to redirect each of the old domains to the new domain instead. These redirects should handle all variants of the old domain names -- for example, www.olddomain.com and olddomain.com -- at a minimum.

You should also pick either the www subdomain or the main (non-www) domain of your new domain as your canonical domain name, and redirect from the non-canonical version to the canonical version. In other words, pick newdomain.com or www.newdomain.com, and redirect all other domains to that one.

Having done that, make sure that you link only to the canonical domain -- Do not link to the non-canonical domains after redirecting them. Where possible, ask other webmasters to correct their links to your site if they are linking to a non-canonical domain variation.

You may also wish to redirect non-canonical page URLs to their canonical URLs. For example, 301-redirect "/index.html" to "/".

The goal in all cases is that each page on your site should have one URL and one URL only; all other possible variations should redirect to that one URL. This avoids problems with "duplicate content" in the search engines.

Jim

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3491779 posted 2:15 am on Nov 12, 2007 (gmt 0)

Now that the canonical redirects are in place, do be aware that Google will take many months to drop the "incorrect" URLs from their index.

That is not a problem as your redirect always takes the visitor through to the correct place on your site anyway.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved