Forum Moderators: phranque

Message Too Old, No Replies

Apache HTTP Server redirect using mod rewrite

mod_rewrite

         

sniper55

10:34 am on Feb 6, 2015 (gmt 0)

10+ Year Member



Hi,

I am trying to redirect a site to a new site but have a few issues:-

For example I want to redirect:
http://dev.example.com/page?Id=12345
to
http://dev.othersite.com/page?param=12345

This is what I have configured in httpd.conf:-


RewriteEngine on
RewriteCond %{HTTP_HOST} dev.example.com [NC]
RewriteRule ^(.*)$ http://dev.othersite.com:9011/$1 [R=301,L]


TESTS
If I enter http://dev.example.com/ in the browser I get the Apache index.html page. I am not sure why?

If I enter http://dev.example.com/something in the browser I get page not found which I expect

If I enter http://dev.example.com/echoTest in the browser I get the expected page and the redirect works

If I enter http://dev.example.com/console in the browser I get "unable to connect" ... I expect that is because http://dev.othersite.com:9011/console returns a 403? Does that make sense?

Any help/pointers much appreciated! (I realise I haven't addressed the query_string yet but that can wait..)

Many thanks
simon

[edited by: Ocean10000 at 5:03 pm (utc) on Feb 6, 2015]

[edited by: phranque at 11:03 pm (utc) on Feb 6, 2015]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]

sniper55

11:32 am on Feb 6, 2015 (gmt 0)

10+ Year Member



I am not sure what happened to my post.

[dev.othersite.com...] should read http://dev.othersite.com:9011/page?param=12345

TESTS
If I enter http://dev.example.com/ in the browser I get the Apache index.html page. I am not sure why?

If I enter http://dev.example.com/test in the browser I get page not found which I expect

If I enter http://dev.example.com/echo in the browser I get the expected page and the redirect works

If I enter http://dev.example.com/console in the browser I get "unable to connect" ... I expect that is because http://dev.othersite.com:9011/console returns a 403? Does that make sense?

[edited by: Ocean10000 at 5:07 pm (utc) on Feb 6, 2015]
[edit reason] Breaking links to make easier to read [/edit]

lucy24

8:17 pm on Feb 6, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For starters:

#1 Where is the RewriteRule located? Loose in the config file, or in a <Directory> section corresponding to the root of the domain you're working with?

#2 Is the server for othersite.com listening on port 9011?

If you need to talk about more than one site without auto-linking, you can say example.org, example.net, or example.any-tld-you-can-think-of. Unfortunately you can't use subdomains unless you intentionally "break" the URL or put it in [ code ] markup.

phranque

8:31 pm on Feb 6, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Unfortunately you can't use subdomains unless you intentionally "break" the URL or put it in [ code ] markup.

that was fixed quite a while ago.
e.g. http://subdomain.example.co.uk/

phranque

2:26 am on Feb 7, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, sniper55!


are you clearing your browser cache before testing your mod_rewrite changes?

lucy24

5:22 am on Feb 7, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



that was fixed quite a while ago

Dang. I'd got so used to it not working, I never even re-checked :)

http://subdomain.example.com/pagename.html

Whee!

sniper55

10:21 am on Feb 9, 2015 (gmt 0)

10+ Year Member



#1 Where is the RewriteRule located? Yes loose in the config file although I am planning on moving it to a virtualhost section.

#2 Is the server for othersite.com listening on port 9011? Yes

Thanks to those who have replied. I have fixed it now:-

RewriteEngine on
RewriteCond %{HTTP_HOST} dev.example.com [NC]
RewriteRule (.*)$ http://dev.othersite.com:9011$1 [R=301,L]


I think caching was also an issue!