Message Boards

Redirect to non www to www version

nidheesh ks, modified 12 Years ago.

Redirect to non www to www version

New Member Posts: 23 Join Date: 7/26/11 Recent Posts
Hi ,

I have multiple portal instances.
For a instance Ii gave virtual host without "www", then created an organization in the instance and I gave virtual host with "www" .
Now I want all my request to be redirected to "www" version if at all the user does'nt enter it in the url

Thanks in advance,

Nidheesh
thumbnail
Ravi Kumar Gupta, modified 12 Years ago.

RE: Redirect to non www to www version

Liferay Legend Posts: 1302 Join Date: 6/24/09 Recent Posts
I have no idea on how to do this on just tomcat or so.. but using a web server in front it can be done... see this http://www.scriptalicious.com/blog/2009/04/redirecting-www-to-non-www-using-htaccess/
nidheesh ks, modified 12 Years ago.

RE: Redirect to non www to www version

New Member Posts: 23 Join Date: 7/26/11 Recent Posts
Hi Ravi,
Thanks for you reply.
I understand what you mean , but for that i have to install apche on my server and proxy all request to tomcat right?.
I saw that when we type "liferay.com" in browser it gets redirected to "www.liferay.com", so I think there may be another way, or else liferay website is also doing the same with apache redirect.

Thanks
thumbnail
Ravi Kumar Gupta, modified 12 Years ago.

RE: Redirect to non www to www version

Liferay Legend Posts: 1302 Join Date: 6/24/09 Recent Posts
nidheesh ks:

I understand what you mean , but for that i have to install apche on my server and proxy all request to tomcat right?.

You are right.. emoticon

nidheesh ks:

I saw that when we type "liferay.com" in browser it gets redirected to "www.liferay.com", so I think there may be another way, or else liferay website is also doing the same with apache redirect.

I guess Liferay is using CDN.. check all the requests of a page when you open liferay.com emoticon
nidheesh ks, modified 12 Years ago.

RE: Redirect to non www to www version

New Member Posts: 23 Join Date: 7/26/11 Recent Posts
Hi,

For getting into a solution for this I tried creating a servlet filter which redirects all request coming without www to www.
Then I added it to liferay web.xml and the jar to lib folder and it seems working.
The only thing I missed is the order of the filter chain. Although my filter is defined first it is coming after vitual host filter I think, because www is getting appended but "web/org-name" is coming with it .
qingsheng fu, modified 11 Years ago.

RE: Redirect to non www to www version

New Member Posts: 11 Join Date: 3/25/11 Recent Posts
you can use the url rewriter. in the ROOT/WEB-INF, find the urlrewite.xml and add a new rule

<rule>
<name>Domain Name Check</name>
<condition name="host" operator="notequal">www.example.com</condition>
<from>^(.*)$</from>
<to type="redirect">http://www.example.com$1</to>
</rule>
thumbnail
Dominik domih, modified 10 Years ago.

RE: Redirect to non www to www version

Junior Member Posts: 57 Join Date: 11/10/08 Recent Posts
Thank you qingsheng! You redirect everything except www.example.com to http://www.example.com.

I wanted to share my modified version, which redirects naked URLs to www URLs for single domain names like example.com.

        <rule>
                <name>Domain Name Check for example.com</name>
                <condition name="host" operator="equal">^example.com</condition>
                <from>^(.*)$</from>
                <to type="redirect">http://www.example.com$1</to>
        </rule>

This redirects non-www URLs to www URLs. So every pagehit that comes to example.org gets redirected to www.example.org. With this you can have multiple domains on one server.
Ghazala sabir, modified 7 Years ago.

RE: Redirect to non www to www version

New Member Posts: 3 Join Date: 9/3/15 Recent Posts
I used below Redirect URL rule but its also redirect wrong url to my site.
For example its redirect zzzzzzz.example.com to my site.This is not what I want.Please suggest

<rule>
2 <name>Domain Name Check for example.com</name>
3 <condition name="host" operator="equal">^example.com</condition>
4 <from>^(.*)$</from>
5 <to type="redirect">http://www.example.com$1</to>
6 </rule>