I’m having difficulty constructing a non-www to www permanent redirect. Here are the conditions I need to meet…
1.) Multi-domain support (multiple website domains pointed at the same directory on a server with their own dedicated copy of a database). This means using %{HTTP_HOST} and NOT a static domain name.
2.) ALL possible pathes (or at least standards compliant ones) need to redirect; this means directories, HTTP queries, etc.
3.) I’m using shared hosting, so I have access to the .htaccess file only.
Here is what I’m working with right now:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^%{HTTP_HOST}
RewriteRule (.*) http://www\.%{HTTP_HOST}/$1 [R=301,L]
Details:
-
I’m testing with the browser cache disabled just in case.
-
I’ve removed other syntax during testing to see what replies work in their own right.
Here you go:
It will also keep the URI scheme.