Forum Moderators: phranque

Message Too Old, No Replies

Force WWW on domain alias

         

sid_o

8:49 am on Jul 9, 2009 (gmt 0)

10+ Year Member



Hi,
I have an htaccess file that suposed to force the use of WWW in the URL.
This works fine on the main domain of the server, however i have a domain alias which when i access it with WWW in the address there is no problem however when i try withour WWW the htaccess redirection is not working.

Any ideas are welcome,
Thanks.
Here is my htacces code:

RewriteEngine on

RewriteRule ^$ /index.php [L]
RewriteCond $1 !^(index\.php¦images¦css¦scripts¦lib¦audio¦flash¦Js¦guide¦docs¦robots\.txt¦favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) [%{HTTP_HOST}...] [NC]

jdMorgan

1:08 pm on Jul 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



These rules are not in the correct order, there appears to be a redundant rule, and a dangerous rewriterule flag error that results in a 302 redirect instead of the 301 that you want search engines to see. Try:

RewriteEngine on
#
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#
RewriteCond $1 !^(index\.php¦images¦css¦scripts¦lib¦audio¦flash¦Js¦guide¦docs¦robots\.txt¦favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]

Also, be sure that the "alias domain" resolves to the directory where this .htaccess file resides. If it does not, then this code won't have any effect on alias domain requests.

In general, you want to put all external redirects first in your .htaccess file, in order from most-specific pattern to least-specific, followed by all internal rewrites, again in order from most-specific pattern to least-specific pattern.

Replace all broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

sid_o

2:25 pm on Jul 9, 2009 (gmt 0)

10+ Year Member



Thanks Jim,
i have changed the code as you auggested & it is realy more logical & even solved a different issue i had, however it still doesnt affect the domain alias.

this means that when i go to the alias domain in this form: [alias.com...] i get to the correct page & i know that the htaccess in working for this domain becuase it knows that if i go to [alias.com...]
it is actually [alias.com...] .
However still when i try to go to [alias.com...] i don't get transfered.

any ideas?

jdMorgan

2:45 pm on Jul 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to work through the DNS settings and the server configuration to find out why the alias.com domain isn't pointing to this .htaccess file's directory as DocumentRoot, then.

If this code executes, it will work. So it's evidently not being executed when you request alias.com. The cause of this problem lies outside of this .htaccess file.

Jim

sid_o

3:17 pm on Jul 9, 2009 (gmt 0)

10+ Year Member



Thanks a lof for the help Jim