Foros de discusión

Redirect to non www to www version

nidheesh ks, modificado hace 12 años.

Redirect to non www to www version

New Member Mensajes: 23 Fecha de incorporación: 26/07/11 Mensajes recientes
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, modificado hace 12 años.

RE: Redirect to non www to www version

Liferay Legend Mensajes: 1302 Fecha de incorporación: 24/06/09 Mensajes recientes
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, modificado hace 12 años.

RE: Redirect to non www to www version

New Member Mensajes: 23 Fecha de incorporación: 26/07/11 Mensajes recientes
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, modificado hace 12 años.

RE: Redirect to non www to www version

Liferay Legend Mensajes: 1302 Fecha de incorporación: 24/06/09 Mensajes recientes
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, modificado hace 12 años.

RE: Redirect to non www to www version

New Member Mensajes: 23 Fecha de incorporación: 26/07/11 Mensajes recientes
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, modificado hace 11 años.

RE: Redirect to non www to www version

New Member Mensajes: 11 Fecha de incorporación: 25/03/11 Mensajes recientes
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, modificado hace 10 años.

RE: Redirect to non www to www version

Junior Member Mensajes: 57 Fecha de incorporación: 10/11/08 Mensajes recientes
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, modificado hace 7 años.

RE: Redirect to non www to www version

New Member Mensajes: 3 Fecha de incorporación: 3/09/15 Mensajes recientes
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>