zend-frameworkmod-rewriterouterhostnamehttp-host

How to make 'www' optional in a Hostname Route in Zend?


Let's say I have the domain "example.com" I would like to add a route such as when the URL is "example.com/whatever/follows" it redirects to "http://www.example.com/whatever/follows" (forwarding the query strings too).

Basically I would like to translate into Zend the following Apache Rewrite rule:

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]

How can we do that if possible at all?

Cheers,


Solution

  • I would recommend to keep it as a apache rule, as it is faster and is the correct way to do. WWW is actually a subdomain value not an optional feature and it should not be present, unless you want the subdomain.

    Also check the no-www site.