Getting rid of www. and 301 redirect.

 
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting
View previous topic :: View next topic  
Author Message
cenocre
-


Joined: 12 Mar 2007
Posts: 47

PostPosted: Mon Jul 14, 2008 2:40 pm    Post subject: Getting rid of www. and 301 redirect. Reply with quote

To optimize search engine rankings, I wish to 301 redirect for www.domain.com to domain.com. Other than the lack of easy log archiving this is one of the last hurdles in moving all of our servers to Abyss from Apache.

Can I do one central rule for the entire server to handle all domains generically as I can for mod-rewite? If so, how?

If doing it for each virtual host, in a case where a virtual host configuration is presently:
Quote:
<names>
<name>
domain.com
</name>
<name>
www.domain.com
</name>
</names>

Do I just put the rewrite rule with this configuration or do I have to do separate virtual host configurations for each www.domain.com and domain.com?

What if the virtual host config is like this?
Quote:
<names>
<name>
*domain.com
</name>
</names>


I'm fairly new to this so any help on what the actual rewrite string looks like that does a 301 redirect from www.domain.com to domain.com would be GREATLY appreciated.
Back to top View user's profile Send private message
AJWesley
-


Joined: 13 Jan 2008
Posts: 39
Location: Kentville, Nova Scotia, Canada

PostPosted: Sun Jul 27, 2008 4:19 pm    Post subject: Re: Getting rid of www. and 301 redirect. Reply with quote

cenocre wrote:
I'm fairly new to this so any help on what the actual rewrite string looks like that does a 301 redirect from www.domain.com to domain.com would be GREATLY appreciated.

This is going to be long, sorry.

Here is the kicker, and one pure pain in the rear! ...
First I noticed that if I entered aprelium[dot]com (as an example, and I am using the [dot] to prevent this post from interfering with Aprelium's SEO) the domain would redirect to, www[dot]aprelium[dot]com/, which is exactly what I wanted to achieve in my own domain redirect! However, if I enter, aprelium[dot]com/// in a browser address bar the domain redirects to www[dot]aprelium[dot]com///, and furthermore if I enter www[dot]aprelium[dot]com/// in a browser address bar the domain remains as www[dot]aprelium[dot]com///, rather strange and not at all what I want...

I want my_domain[dot]com to redirect permanently to www[dot]my_domain[dot]com/, minus the multiple slashes.

First, and acting on the advice of Aprelium Technical Support, I created two domains: my_domain[dot]com and www[dot]my_domain[dot]com.
I left my website, document folder, etc., empty in my_domain[dot]com and used the "URL Rewriting Rules - Edit" feature to redirect permanently to www[dot]my_domain[dot]com, which serves my website, documents, scripts, etc. The rewrite rule provided worked like a charm, except for the multiple trailing slashes (as indicated above).
---
Here is my "fix" of sorts.
Using the "URL Rewriting Rules - Edit" feature I added to my[dot]domain[dot]com the following:
Virtual Path Regular Expression: ^/*(([^/]+/)*)/+(.*)$
Case Sensitive: Not Checked
Conditions: None Included
Apply to subrequests too: Checked
If this rule matches: Perform an external redirection
Redirect to: //www[dot]my_domain[dot]com/$1$3
Append Query String: Checked
Escape Redirection Location: Checked
Status Code: 301 - Moved Permanently
---
This worked like a charm! I tried to screw it up with many insane variations, some listed below:
my_domain[dot]com//, my_domain[dot]com/index.html//, /my_domain[dot]com//index.html////, and each redirected to either www[dot]my_domain[dot]com/ or www[dot]my_domain[dot]com/index.html/ without fault. But herein lies my problem now, if I enter any insane variation of the above but with the www, as in www[dot]my_domain[dot]com//index.html/// in a browser address bar the domain remains as www[dot]my_domain[dot]com//index.html/// (as an example), and back to square one. I solved the original problem, which pleases me no end, but I still have the multiple slashes with "www" as indicated in the www[dot]aprelium[dot]com/// example above.

I apologize for the long post, but I figure this is a problem with many a user on this forum and I would like to put it to rest here, for the last time.

1. How do I remove any and all-multiple slashes, trailing and otherwise, from www[dot]my_domain[dot]com/, now that my_domain[dot]com is no longer a problem?

2. How do I redirect any trailing instance of index.*, home.*, etc. to www[dot]my_domain[dot]com/ as first entry (the landing or doorway) to my website?

The first question is a priority, and "cenocre", just remove the www from my example (reverse order) and you have your answer.

~AJ~
_________________
"A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila..."
Back to top View user's profile Send private message MSN Messenger
rrinc
-


Joined: 24 Feb 2006
Posts: 725
Location: Arkansas, USA

PostPosted: Sun Jul 27, 2008 11:46 pm    Post subject: Reply with quote

This guy wanted his domain to redirect from www.domain to just domain (no www), not the other way around.

Check this site out: http://no-www.org/faq.php
Using their terminology he wants class B.
I barely understand regex, so someone can translate this for Abyss:
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

_________________
-Blake | New Server :D
SaveTheInternet
Soy hispanohablante. Puedes contactarme por mensajes privados.
Back to top View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
AJWesley
-


Joined: 13 Jan 2008
Posts: 39
Location: Kentville, Nova Scotia, Canada

PostPosted: Mon Jul 28, 2008 12:01 am    Post subject: Reply with quote

rrinc wrote:
This guy wanted his domain to redirect from www.domain to just domain (no www), not the other way around.

Check this site out: http://no-www.org/faq.php
Using their terminology he wants class B.
I barely understand regex, so someone can translate this for Abyss:
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


Hey rrinc, thanks for the link :) I meant that cenocre could simply do the following, instead of what I am using for my domain redirection:

Add to www[dot]my_domain[dot]com the following:
Virtual Path Regular Expression: ^/*(([^/]+/)*)/+(.*)$
Case Sensitive: Not Checked
Conditions: None Included
Apply to subrequests too: Checked
If this rule matches: Perform an external redirection
Redirect to: //my_domain[dot]com/$1$3
Append Query String: Checked
Escape Redirection Location: Checked
Status Code: 301 - Moved Permanently

~AJ~
_________________
"A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila..."
Back to top View user's profile Send private message MSN Messenger
AJWesley
-


Joined: 13 Jan 2008
Posts: 39
Location: Kentville, Nova Scotia, Canada

PostPosted: Wed Aug 06, 2008 2:37 pm    Post subject: Reply with quote

rrinc wrote:
This guy wanted his domain to redirect from www.domain to just domain (no www), not the other way around.

Check this site out: http://no-www.org/faq.php
Using their terminology he wants class B.
I barely understand regex, so someone can translate this for Abyss:
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


I finally got totally pissed with this ~reg ex/re write crap~ and trying to match one example (friendly?) to one server flavor and another... then another...
Here's one rule that *all* servers understand and is simple to grasp for the newbie. Originally "cenocre" wanted to "301 redirect www.domain.com to domain.com."

Well for simplicity and to rank SEO friendly, and to completely remove any possible request for www.domain.com -- or directory -- or file -- or slash, 1,2,3 and more -- whatever... permanently to, domain.com:

Virtual Path Regular Expression: (.*)
Case Sensitive: Not checked
Conditions: None
Apply to subrequests too: Checked
If this rule matches: Perform an external redirection
Redirect to: http://domain.com/
Append Query String: Not checked
Escape Redirection Location: Checked
Status Code: 301 - Moved Permanently

// (.*) matches everything and redirects to domain.com -- the rest is self explanatory.
// Now since www.domain.com is all but dead, you can use your coding mojo and magic skills on your redirect, domain.com -- done with it. (Originally used successfully by Yahoo.)
_________________
"A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila..."
Back to top View user's profile Send private message MSN Messenger
AJWesley
-


Joined: 13 Jan 2008
Posts: 39
Location: Kentville, Nova Scotia, Canada

PostPosted: Wed Aug 06, 2008 2:46 pm    Post subject: Give it a ride. Reply with quote

1st rule:
------
Virtual Path Regular Expression: ^(.*)index.(htm|html|php|)
Case Sensitive: Not checked
Conditions: None
Apply to subrequests too: Checked
If this rule matches: Perform an external redirection
Redirect to: http://domain.com/
Append Query String: Not checked
Escape Redirection Location: Not checked
Status Code: 301 - Moved Permanently

//redirects request for index.* (as listed above) to root URI
(change http://domain.com/ to http://www.domain.com/ if required).
------

2nd rule:
------
Virtual Path Regular Expression: ^/*(([^/]+/)*)/+(.*)$
Case Sensitive: Not checked
Conditions: None
Apply to subrequests too: Checked
If this rule matches: Perform an external redirection
Redirect to: http://domain.com/$1
Append Query String: Not checked
Escape Redirection Location: Not checked
Status Code: 301 - Moved Permanently

//removes multiple slashes from root URI, directory and file,
redirects to http://domain.com/ (change to http://www.domain.com/ if required).
------
I'm just curious to see where this goes -- always willing to share and to learn another trick or two...
_________________
"A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila..."
Back to top View user's profile Send private message MSN Messenger
maxnorris
-


Joined: 20 Sep 2008
Posts: 1

PostPosted: Sat Sep 20, 2008 7:12 pm    Post subject: Reply with quote

I'm just getting started with Abyss myself, but a little stuck with the rewrites as well.

I want to go in the opposite direction; append a www if none is given in the URL. I can almost get it, but not quite.

The original Apache version would be

Code:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]


I'm sure it's a problem with one of the parameters; either gets into a loop or comes back with a bad URL.

Thanks
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group