Forum Moderators: phranque

Message Too Old, No Replies

non-www redirect to www question.

         

Dreamgun

3:51 am on Jan 19, 2010 (gmt 0)

10+ Year Member



Hello, new to the whole htaccess redirect thing. Anyways, first question is... how necessary is it for me to direct anyone accessing my site without a www to www? As in... [domain.com...] -> [domain.com....]

Next question is, what is the difference between these two statements:

RewriteRule (.*) [domain.com...] [L,R=301]
or
RewriteRule (.*) [domain.com...] [L,R=premanent]

I have seen either of the above also with "L" at the end.
"[R=permanent,L]"

Here is what I have experimented with in my htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^domain.com
RewriteRule (.*) [domain.com...] [L,R=301]

It works, but if you type domain.com/directory in your browser and this directory you have pointed to is a sub-domain with redirection to a site, I get a "requested URL /403.shtml was not found on this server."

I have a shared hosting account using cpanel, the sub-domains I have setup redirection from cpanel had setup these htaccess files in the subdomain directories:
---------------
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain1.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.subdomain1.domain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.domain\.com" [R=301,L]

<Files 403.shtml>
order allow,deny
allow from all
</Files>
----------------

All that being said I generally have two main questions:
1. How necessary to redirect from non-www to www?
2. What needs to be changed so visiting the subdomain's folder from domain.com/directory will work as if visiting subdomain.domain.com?

As visiting the sub-domain directly: subdomain.domain.com follows through with its correct redirection, just giving the 403 error when using htaccess redirection from domain.com/directory.

jdMorgan

5:47 am on Jan 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> What's the difference between these two lines?

They are equivalent, except that the second line won't work because "permanent" is misspelled.

RewriteRule flags may be specified in any order, and "301" and "Permanent" are synonyms. See the mod_rewrite documentation at apache.org for authoritative information.

1. It is not at all necessary to redirect non-www to www or vice-versa, unless you care about your rankings in search engines. Otherwise, see the threads in our Google Search forum such as "Duplicate content -- Get it right or perish."

2. If a subdomain is assigned a "folder under a master domain," then any attempt to directly-access that folder-filepath should be disallowed or redirected back to the canonical subdomain URL. For details, see the threads cited in #1 just above.

To state a simple rule, for any given 'piece of content' on the Web, it should be accessible by one and only one URL, and no variations whatsoever in the URL that appears in the browser address bar should be allowed. Requests for any variations in protocol, subdomain, domain, tld, FQDN-format, port number, URL-path, query string, or named anchor (a.k.a. "fragment") --to include casing errors-- should be redirected to the correct single/canonical URL.

Your missing 403.shtml file needs correction immediately as well. Either create a custom 403 error page, or disable the custom 403 error page in your control panel and use the Apache default 403 response.

The best line of mod_rewrite code created by your control panel is the first RewriteCond, since it only contains two syntactical errors and one logic error. The others are worse. They're so badly-coded I won't comment further, other than to suggest that you look around in this forum for better examples and use the documentation cited above to examine/analyze the differences. Sadly, this is the state of control panels today...

Jim

g1smd

9:54 am on Jan 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



See the last part of the question I just answered at: [webmasterworld.com...]