Foren

Redirect to non www to www version

nidheesh ks, geändert vor 12 Jahren.

Redirect to non www to www version

New Member Beiträge: 23 Beitrittsdatum: 26.07.11 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Redirect to non www to www version

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Redirect to non www to www version

New Member Beiträge: 23 Beitrittsdatum: 26.07.11 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Redirect to non www to www version

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Redirect to non www to www version

New Member Beiträge: 23 Beitrittsdatum: 26.07.11 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: Redirect to non www to www version

New Member Beiträge: 11 Beitrittsdatum: 25.03.11 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: Redirect to non www to www version

Junior Member Beiträge: 57 Beitrittsdatum: 10.11.08 Neueste Beiträge
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, geändert vor 7 Jahren.

RE: Redirect to non www to www version

New Member Beiträge: 3 Beitrittsdatum: 03.09.15 Neueste Beiträge
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>