[Sussex] htaccess & 301s
Steve Dobson
steve.dobson at syscall.org.uk
Thu Oct 22 01:24:12 UTC 2009
Hi Dominic
Dominic Humphries wrote:
> I've got an annoying problem with trying to set up a 301 redirect on a
> website.
>
> It's a SEO thing, they want to avoid having 'www' in their URL. So that
> should be easy enough, you can set up a redirect to send all
> 'www'-containing addresses to the non-www alternative.
>
> Problem is, all the redirects seem to follow this format:
>
> rewritecond %{http_host} ^www.domain.com [nc]
> rewriterule ^(.*)$ http://domain.com/$1 [r=301,nc]
>
> And this site needs to have some pages secure, i.e. accessed via httpS -
> and the above code always redirects to plain http.
>
> Is there any way to set up a redirect so any attempt to access
> www.domain.com gets sent to domain.com, but everything else gets left
> alone? Or failing that, a way to stop it redirecting https requests?
I didn't use the htaccess files, but did it within the "VirtualHost"
config. My needs were much easier, I wanted to redirect any "http"
access to the "https" stream, but I would think you can have many
"RewriteRule"s to meet your needs.
<VirtualHost www.example.com:80>
ServerAdmin webmaster at example.com
ServerName example.com
DocumentRoot /var/www
RewriteEngine on
RewriteRule ^.*$ https://example.com
CustomLog /var/log/apache2/access.log combined
ServerSignature On
</VirtualHost>
<VirtualHost www.example.com:443>
ServerAdmin webmaster at example.com
# Config for the virtual host that serves the web pages
</VirtualHost>
More information about the Sussex
mailing list