Here's a little tip for people using Apache with multiple domains pointed to a single site (even if it's just www.yourdomain.com and yourdomain.com). This can be used within your apache (or site) conf file on the server (changing the items to work with your domain/IP address of course). <VirtualHost 192.168.1.1> ServerName [url]www.yourdomain.com[/url] ServerAlias [url]www.anotherdomain.com[/url] yourdomain.com RewriteEngine on RewriteCond %{HTTP_HOST} !^192.168.1.1(:80)?$ RewriteCond %{HTTP_HOST} !^www.yourdomain.com(:80)?$ RewriteRule ^/(.*) http://www.yourdomain.com/$1 [L,R=301] </VirtualHost> Code (markup): What that will do is redirect any request within the domains defined in ServerAlias to the correct location within the main domain using a search engine friendly 301 redirection. This is nice because you don't have to have tons of rewrites, and it also makes search engines happy because you aren't replicating content. - Shawn
So... what if we are on a shared server, and have no access to the config file or the root directory? Can this be done with the htaccess file in the home directory of a shared server?
Yes, you should be able to do it within the .htaccess file as well. Although I've never done it at that level myself, so I can't offer an example. But pretty much if you just use the RewriteCond and RewriteRule lines, I think you would be okay.
In a word, Yes. My own local .htaccess files deal with a more restricted case, that of just the presence or absence of the leading "www.". They typically look like this: RewriteCond %{HTTP_HOST} www.seo-toys.com RewriteRule ^(.*) http://seo-toys.com/$1 [L,R=301] The ones presented in the post above are more general in scope, and essentially, as I understand it, redirect any call that is not exactly what you want to the one that is exactly what you want. That is, the conditions-- !^192.168.1.180)?$ !^www.yourdomain.com80)?$--specify that anything that is not Port 80 on either 192.168.1.1 or www.yourdomain.com is something to rewrite to: http://www.yourdomain.com/$1(where the $ stuff means plug in whatever follows).
I want to use this on my shared server... are those two lines of code all I have to add to my .htaccess file? Or is there more? sorry for my ignorance, I've never really done much stuff like this
i have access to my conf file but have already done the htaccess redirection instead? Would you say it is better for me to move the redirection to the conf file? and why? al2six.... i just did that to my htaccess and it worked fine. Just them two lines of code
It doesn't seem to be working for me... Here is the entire contents of my htaccess file: RewriteCond %{HTTP_HOST} www.musicgearmaster.com RewriteRule ^(.*) http://musicgearmaster.com/reviews/drums/$1 [L,R=301] It should take you to the nonexistant folder reviews/drums but it still just takes you to the index page. Any ideas why it isn't working?
We have two domains per site, one is our own URL and one is a subfolder of the big shopping portal who provide our ecommerce solution. I get the impression (Shawn's Tool confirms it) that Google likes the pages in the subfolder better than those in our own URL. Is there any reason why Google would prefer pages from a domain with thousands of pages over the exact same page on a domain with just a few hundred? Amazon seems to appear in a lot of top 10 listings, does G take website size into account when it comes to calculating SERPs? I'm debating which one to choose if we do want to redirect the other... Any ideas?
Remember to enable the rewrite engine in the first place.. (you'll notice the line in Shawns original post).. try: --snip-- RewriteEngine on RewriteCond %{HTTP_HOST} www.musicgearmaster.com RewriteRule ^(.*) http://musicgearmaster.com/reviews/drums/$1 [L,R=301] --snip-- Cheers, JL.
thanks! that worked. however it didn't do quite what I want it to do... I have more than one domain on that server. Each domain is for a seperate site and should point to a folder containing the content for that site. so when you type in www.musicgearmaster.com, i want it to take you to www.musicgearmaster.com/reviews/index.php. But if i use the following... RewriteCond %{HTTP_HOST} www.musicgearmaster.com RewriteRule ^(.*) http://musicgearmaster.com/reviews/$1 [L,R=301] Then if you type in the exact filename of a page (ie www.musicgearmaster.com/reviews/index.php) it will try to take you to www.musicgearmaster.com/reviews/reviews/index.php anyone have a solution for this?
But the index page for the site is in the reviews folder. If I take off the reviews, when you type in the domain, it will take you to index.php (which is the index for another site on the server) instead of reviews/index.php which is the correct index page.
Will doing this; as you demonstrate: RewriteCond %{HTTP_HOST} www.seo-toys.com RewriteRule ^(.*) http://seo-toys.com/$1 [L,R=301] Cause google to change any backlinks going to www to end up with the non-www backlinks it has picked up? Do I even make sense?:O In other words: the majority of my backlinks go to domainname.com as opposed to www.domainname.com - I have 5 or 6 strays that I would really like to show up under the domainname.com backlinks. Thanks for the above string. I've been trying for 2 days to get a 301 redirect to work the way I want it to. Regards; Flawebworks
I made an error and only copied the 4 Rewrite lines, leaving off the ServerAlias line. I already had a similar ServerAlias line, but one with only one argument in it. I also have a ServerName line. My code, therefore, looks like this: ServerName www.internet-search-engines-faq.com ServerAlias internet-search-engines-faq.com RewriteEngine on RewriteCond %{HTTP_HOST} !^216.17.194.115(:80)?$ RewriteCond %{HTTP_HOST} !^www.internet-search-engines-faq.com(:80)?$ RewriteRule ^/(.*) http://www.internet-search-engines-faq.com/$1 [L,R=301] Code (markup): Works just the same with the slightly different syntax.
Will, Is the second version of the code you last posted in this thread the .htaccess equivalent of the code above that would be from an httpd.conf file?
ok - I can't seem to get this to work...... Give me an example based on the following senario.... All pages of .net are moving to .com So I need an example using all pages of: www.from.net from.net redirect to: www.destination.com
Heck, this is more complex than you need for that. Just put this one line in the .htaccess file for your .net domain: Redirect 301 / http://www.destination.com/ Code (markup):