Rule syntax needed - force www, but more

Topics: User Forum
Jun 23, 2011 at 1:14 AM

I need a 301 reDIRECT rule that converts this:

to this:


we also have a reWRITE rule which handles not having the "central controller" in the url, like so:

internally becomes:

Right now, if someone enters

we're getting a 301 redirect that ends up as:

and what we want is:

is this possible without multiple redirects?

Jun 23, 2011 at 11:17 AM

What rules are you already using?

Your redirect should easily just add on the www. and append whatever is existing on the URL to the end, ie. => for your rewriterule to then pick up on.

Jun 23, 2011 at 12:23 PM

Below are current rules, but as I said, they are behaving as described above and not quite the way we'd like:


# Force www into URL
RewriteCond %{HTTP_HOST} ^(?!www)[^\.]+\.[^\.]+$ [I]
RedirectRule ^/(.*) http://www.%{HTTP_HOST}/$1 [R=301]

# Allow urls without controller.cfm central controller
RewriteRule (^/(flex2gateway|jrunscripts|cfide|cfformgateway|images|robots.txt|controller.cfm)($|/.*$)) $1 [L,I]
RewriteRule ^/(.*)$ /controller.cfm/$1 [L]


To repeat... with the above rules if someone enters

we're getting a 301 redirect that ends up as:

and what we want is:

Jun 23, 2011 at 12:32 PM

I thought that you could capture the http_host in the rewritecond. Bit of a guess here...

RewriteCond %{HTTP_HOST} ^(?!www\.)([^\.]+\.[^\.]+)$ [I]

RedirectRule ^/(.*) http://www.%2/$1 [R=301]

I *think* that this will capture the http_host in the rewritecond and pass it to the redirect. Note the 2 capture groups.

There will be something about this in the documentation, but I'm sorry, I don't have time to look right now.

Hope this helps.

Jun 23, 2011 at 12:36 PM

ummm... we already HAVE that rule... it's the first block in the reply I posted, under "Force www into URL".  :)

Also, your rule redirects to for some reason... ours is working, we just want it to work without controller.cfm in it when processing to add the www.  Please re-read my post(s) when you get some time.  I *do* appreciate your replies though!!!

Jun 23, 2011 at 12:39 PM

It doesn't have the brackets to capture the 2nd group though... There is a difference.

I'm hoping that Cheeso will step in at some point as he is the main man...

Maybe try:

RewriteCond %{HTTP_HOST} ^(?!www\.)?([^\.]+\.[^\.]+)$ [I]

so that the www. is not necessary...