Forum Moderators: phranque

Message Too Old, No Replies

Difference in 301

         

wusin

7:19 pm on Dec 26, 2004 (gmt 0)

10+ Year Member



Any one know the difference in between:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST}!^www\.domain\.com
RewriteRule ^(.*)$ [domain.com...] [R=301,L]

and

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ [domain.com...] [R=301,L]

Thanks.

wusin

7:23 pm on Dec 26, 2004 (gmt 0)

10+ Year Member



Repost to correct the spacing mistake on!^www

Any one know the difference in between:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST}!^www\.domain\.com
RewriteRule ^(.*)$ [domain.com...] [R=301,L]

and

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ [domain.com...] [R=301,L]

Thanks.

jdMorgan

7:42 pm on Dec 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Any one know the difference in between:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

and

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

The first one says, "If not my primary domain, redirect to my primary domain" while the second one says, "If a specific secondary domain, redirect to my primary domain."

So, the first method can redirect many alternate domains and subdomains to your preferred domain, while the second method only redirects a specific domain or subdomain to your preferred domain.

BTW, posting on this board removes spaces preceding the "!" character. In order to override that behaviour, either type two spaces, or precede the "!" with Bold-Unbold or Italic-EndItalic style codes. The first method won't survive a "preview" in the post editor, while the second method will.

The same method can be used to 'break' the automatic link-making behaviour of this forum by inserting a style code between "http:" and "//".

Jim

walkman

8:28 pm on Dec 26, 2004 (gmt 0)



Hmmm...I tried it but for some reason it ads an extra / at the end making it www-domain-com// and 404s on the relative pages

jdMorgan

10:51 pm on Dec 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Walkman,

That's because you're trying to use the code in httpd.conf, I suspect. The code above is written for use in .htaccess, so you'll need to adjust the RewriteRule accordingly.

For use in .htaccess (original, as above):

 RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L] 

For use in httpd.conf, you can change it either of two ways::

 RewriteRule ^[b]/[/b](.*)$ http://www.domain.com/$1 [R=301,L] 

-or-
 RewriteRule ^(.*)$ http://www.domain.co[b]m$[/b]1 [R=301,L] 

Jim

walkman

2:12 am on Dec 27, 2004 (gmt 0)



Thank you again,
I replacedd the other
301 domain.com to www-domain.com with this since it covers this and other subs like mail-domain-com etc. Just in case someone links to it or something. You never know

wusin

2:53 am on Dec 27, 2004 (gmt 0)

10+ Year Member



Thanks Jim,

Just want to clarify my understanding of these,

"If not my primary domain, redirect to my primary domain"
Is that means it will redirect www1, www2, domain.com or other to www.domain.com?

"If a specific secondary domain, redirect to my primary domain"
Is that means it just redirect a specific secondary domain such as www1.domain.com, forum.domain.com and NEVER redirect other like domain.com or [domain.com...] to www.domain.com?

Thanks again Jim.

jdMorgan

3:03 am on Dec 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, I have used the language in a formal way.

However, it is up to you to assign meaning to the term "primary domain", since mod_rewrite will only do a string comparison, and has no "knowledge" about your domains.

Jim

wusin

3:38 am on Dec 27, 2004 (gmt 0)

10+ Year Member



Hi Jim,

One more question, what about if I remove the ^ as below, any effect on it?

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*)$ [domain.com...] [R=301,L]

Thanks.

jdMorgan

4:43 am on Dec 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, in the pattern "^(.*)$", you can remove both the start anchor and the end anchor and use just "(.*)" without any functional effect. For more information, see the regular expressions tutorial cited in our forum charter [webmasterworld.com].

I avoided modifying that part of your code simply because it did not matter, and I don't like to confuse things by introducing side-issues.

Jim

wusin

6:11 am on Dec 28, 2004 (gmt 0)

10+ Year Member



Thank you Jim for the explanation & happy 05.