Forum Moderators: phranque

Message Too Old, No Replies

Redirect through RewriteRule not working

Redirect through RewriteRule not working

         

Tiru

11:27 pm on Jul 30, 2007 (gmt 0)

10+ Year Member



We recently decommissioned one of our site. I want to redirect the request to our parent site.I tried number of ways still these redirects are not working.

Old:
http://www.domain1.com/webapp/wcs/stores/servlet/ProductDisplay?productId=246323&storeId=30003&langId=-1&catalogId=10001
New:
http://www.domain2.com/webapp/wcs/stores/servlet/ProductDisplay?productId=246323&storeId=30003&langId=-1&catalogId=10001

I tried...

RewriteEngine On

RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]

RewriteCond %{QUERY_STRING} ^(.*)productId=([0-9]+)&(.*)$ [NC]

RewriteCond %{HTTP_REFERER} ^domain1.com$ [NC]
RewriteRule ^(.*)$ http://www.domain2.com

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

================================================================================================
RewriteRule ^(.*)ProductDisplay(.*) http://www.domain2.com$1/ProductDisplay/$2 [R=301,L]

================================================================================================

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

I would really appreciate your help in this regard.

Thanks,
Tiru

[edited by: jdMorgan at 1:26 am (utc) on Aug. 2, 2007]
[edit reason] De-linked [/edit]

Tiru

12:45 am on Jul 31, 2007 (gmt 0)

10+ Year Member



Its OK for me if I could manage to redirect to www.domain2.com

Thanks,
Tiru

jdMorgan

1:17 am on Jul 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you wish to redirect all requests from domain1 to www.domain2.com, and domain1 is on a separate server, then all you need is this on domain1:

RewriteEngine on
RewriteRule (.*) http://www.domain2.com/$1 [R=301,L]

If you wish to redirect all requests from domain1 to www.domain2.com, and domain1 is on the same server and resolves to the same directory, then all you need is this:

RewriteEngine on
RewriteCond %{HTTP_HOST} domain1\.com [NC]
RewriteRule (.*) http://www.domain2.com/$1 [R=301,L]

I don't know what the purpose of all of your other code is, but one of the two snippets above will do the docmain redirect you describe for all URLs and query strings.

Jim

[edited by: jdMorgan at 1:27 am (utc) on Aug. 2, 2007]

Tiru

6:36 pm on Jul 31, 2007 (gmt 0)

10+ Year Member



Thanks Jim for the reply...
I tried this option too...these are not working...

We made DNS change to take care of this..those are working fine with domain1.com but failing when user tries with www.domain1.com.

The decommissioned site's content is still there on the server, before taking that off we want to make sure every thing working fine. But when we are trying to redirect with the above specified URL, its taking to the OLD content instead of redirecting this. Any thought on this. I would like to inform that we are set with AllowOveride NONE.Any other thoughts...

Thanks,
Tirumala

jdMorgan

3:35 am on Aug 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> those are working fine with domain1.com but failing when user tries with www.domain1.com

Then your DNS is not correct for www.domain1.com, and/or the server does not deliver requests for www.domain1.com to the same directory as requests for doamin1.com.

Neither of the rules posted above cares whether there is a "www." prefix on the requested hostname, so the problem is in the DNS or server configuration.

Jim

Tiru

4:56 pm on Aug 1, 2007 (gmt 0)

10+ Year Member



is it not possible even though there some problem in DNS config we can override at httpd.conf level.

Tiru

5:23 pm on Aug 1, 2007 (gmt 0)

10+ Year Member



DNS redirect is working fine when there is not path such as /x/y/z?a=1&b=2$c=account appended for ex: domain1.com or domain1.com/x/y/z?a=1&b=2$c=account. when I am redirecting to www.domain1.com/x/y/z?a=1&b=2$c=account this is failing to redirect and landing in OLD content page.

Tiru

5:27 pm on Aug 1, 2007 (gmt 0)

10+ Year Member



We are using IBM HTTP Server v1.3.26

jdMorgan

11:25 pm on Aug 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> is it not possible even though there some problem in DNS config we can override at httpd.conf level.

Certainly not. If there is a DNS problem with a domain or subdomain, the requests for that domain or subdomain won't even reach the server. There won't be any way to redirect them.

Jim

Tiru

1:12 am on Aug 2, 2007 (gmt 0)

10+ Year Member



I readjusted DNS mapping to original for testing purpose but still its not redirecting...its landing on OLD content only.

Tiru

1:18 am on Aug 2, 2007 (gmt 0)

10+ Year Member



My config files looks like this...Is there any way to debug this...

<VirtualHost 61.52.145.103:80>
ServerName www.domain1.com
DocumentRoot D:\Web\html\domain1\en_US
ErrorDocument 404 /404.html
#Redirect 301 / http://www.domain2.com/
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1\.com [NC]
RewriteRule (.*) http://www.domain2.com [L,R=301]
</VirtualHost>

[edited by: jdMorgan at 1:28 am (utc) on Aug. 2, 2007]
[edit reason] De-linked [/edit]

jdMorgan

1:30 am on Aug 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have any other rewriterules that work?

If not, try adding:


Options +FollowSymLinks

before the RewriteEngine on line.

Jim

Tiru

1:59 am on Aug 2, 2007 (gmt 0)

10+ Year Member



No luck...before this it use to miss images, styles etc..once we apply this the OLD page is coming up cleanly...

yes I am having some redirects which are working fine...as I said before the redirect works fine if there are no /x/y/z path to domain...why this is causing problem?

jdMorgan

2:14 am on Aug 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You did not copy my code correctly. Do not anchor the hostname in the RewriteCond pattern.

Also, if this is for use in http.conf, then all you may need is the single line:


RewriteRule (.*) http://www.domain2.com$1 [R=301,L]

You may not need the RewriteCond, because the code is already enclosed in a VirtualHost container.

Jim

Tiru

6:12 pm on Aug 6, 2007 (gmt 0)

10+ Year Member



No luck with the above options...I was not able to understand why its not recognizing this /x/y/z pattern...Every thing working fine when ever we are trying with domains, when the above pattern comes it just lost...nothing happening...landing in same old page...this is really mindboggling.

Tiru

6:17 pm on Aug 6, 2007 (gmt 0)

10+ Year Member



Even I tried this...
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_URI} .
RewriteRule (.*) [domain1.com$1...] [R=301,L]

My trace log is showing... why its taking HTTP 200 i am not able to understand..

[06/Aug/2007:11:11:27 -0700] "GET /favicon.ico HTTP/1.1" 200 894
[06/Aug/2007:11:11:27 -0700] "GET /scripts/dom-drag.js HTTP/1.1" 200 3982
[06/Aug/2007:11:11:27 -0700] "GET /webapp/wcs/stores/servlet/ProductDisplay?productId=246324&storeId=30003&langId=-1&catalogId=10001 HTTP/1.1" 200 19777
[06/Aug/2007:11:11:27 -0700] "GET /scripts/dom-popup.js HTTP/1.1" 200 2398
[06/Aug/2007:11:11:28 -0700] "GET /images/header_02.jpg HTTP/1.1" 404 30284
[06/Aug/2007:11:11:28 -0700] "GET /images/header_01.jpg HTTP/1.1" 404 30284
[06/Aug/2007:11:11:28 -0700] "GET /images/header_04.gif HTTP/1.1" 404 30284
[06/Aug/2007:11:11:28 -0700] "GET /scripts/help_windows.js HTTP/1.1" 200 4777
[06/Aug/2007:11:11:28 -0700] "GET /images/header_03.jpg HTTP/1.1" 404 30284
[06/Aug/2007:11:11:28 -0700] "GET /images/leftnav_10.gif HTTP/1.1" 404 30284
[06/Aug/2007:11:11:28 -0700] "GET /images/header_06.gif HTTP/1.1" 404 16384
[06/Aug/2007:11:11:28 -0700] "GET /scripts/product_item_body.js HTTP/1.1" 200 1127
[06/Aug/2007:11:11:28 -0700] "GET /images/go.gif HTTP/1.1" 200 142
[06/Aug/2007:11:11:28 -0700] "GET /images/spacer.gif HTTP/1.1" 200 43
[06/Aug/2007:11:11:28 -0700] "GET /scripts/common_validations.js HTTP/1.1" 200 1658
[06/Aug/2007:11:11:28 -0700] "GET /images/leftnav_04.gif HTTP/1.1" 404 30284
[06/Aug/2007:11:11:28 -0700] "GET /scripts/product_scripts.js HTTP/1.1" 200 9921
[06/Aug/2007:11:11:28 -0700] "GET /images/leftnav_02.gif HTTP/1.1" 200 430
[06/Aug/2007:11:11:28 -0700] "GET /images/leftnav_06.gif HTTP/1.1" 404 16384
[06/Aug/2007:11:11:28 -0700] "GET /images/full/7665524.jpg HTTP/1.1" 200 31693
[06/Aug/2007:11:11:28 -0700] "GET /images/leftnav_08.gif HTTP/1.1" 404 30284
[06/Aug/2007:11:11:28 -0700] "GET /images/emailtofriend.gif HTTP/1.1" 200 467
[06/Aug/2007:11:11:28 -0700] "GET /images/ecatalog_linkback.gif HTTP/1.1" 200 796

[edited by: Tiru at 6:20 pm (utc) on Aug. 6, 2007]

Tiru

6:33 pm on Aug 6, 2007 (gmt 0)

10+ Year Member



Is there any thing configuration oriented which can stop this /x/y/z overriding? If YES then let me know so that I can verify in my httpd.conf file for that.

jdMorgan

7:01 pm on Aug 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like you don't have the Options directive I asked about above. It is required if you wish to use mod_rewrite.

Jim

Tiru

8:51 pm on Aug 6, 2007 (gmt 0)

10+ Year Member



Thanks Jim for your support in resolving this. Finally I did this through the JSP, as it is not giving me the required redirect through the httpd.conf.