0

Possible Duplicate:
apache redirect from non www to www

I want my domain to redirect the non-www to the www version. For some reason the below code isn't working.

Any suggestions?

Most probably any easy fix, but I can't get it to work.

<ifmodule mod_deflate.c>
<filesmatch \.(css|html|js|php|xml)$>
    setoutputfilter deflate
</filesmatch>
</ifmodule>
<ifmodule mod_security.c>
secfilterengine off
secfilterscanpost off
</ifmodule>

<ifmodule mod_rewrite.c>
    RewriteEngine on
RewriteCond %{HTTP_HOST} ^trailerpulse.com/
RewriteRule (.*) http://www.trailerpulse.com/$1 [R=301,L]
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule ^([a-z]+)(/([^/]{0,32})(/.+)?)?$  index.php?a=$1&q=$3    [L]

</ifmodule>
<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault A0
<filesmatch \.(css|js|gif|jpe?g|png)$>
    ExpiresDefault A604800
</filesmatch>
<filesmatch \.(html|xml)$>
    ExpiresDefault A10800
</filesmatch>
</ifmodule>

FileEtag None
Options All -Indexes
ServerSignature Off
ErrorDocument 404 /error
Community
  • 1
  • 1
Rhys
  • 3
  • 1
  • 3
  • Why are you using mod_rewrite for that? http://stackoverflow.com/questions/1100343/apache-redirect-from-non-www-to-www/1100363#1100363 – Greg Hewgill Oct 04 '12 at 04:13
  • It's the way the code was written when I bought the script the site is based off. – Rhys Oct 04 '12 at 04:17
  • Fair enough. I suggest moving to using the `Redirect` directive as mentioned in that linked question, it's much simpler. – Greg Hewgill Oct 04 '12 at 04:21

1 Answers1

0

Your rule is almost there. The only problem is that you have a trailing slash after the hostname, which would never appear in the "Host:" header of the request. Replace the / with $ and add [NC] flag to ignore case:

RewriteCond %{HTTP_HOST} ^trailerpulse.com$ [NC]
RewriteRule (.*) http://www.trailerpulse.com/$1 [R=301,L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220