0

I need to proxy the URL http://de.domain.com/article1/foobar/ to http://de.foobar.domain.com/article1/.

How can I do this within getting and setting the subdomain language part?

Examples:

http://de.domain.com/article1/foobar/ => http://de.foobar.domain.com/article1/
http://dk.domain.com/article1/foobar/ => http://dk.foobar.domain.com/article1/
http://en.domain.com/article1/foobar/ => http://en.foobar.domain.com/article1/
http://el.domain.com/article1/foobar/ => http://el.foobar.domain.com/article1/

I heard this is not possible only with mod_proxy and I have to use mod_rewrite for this. But I don't know how. Maybe someone can post an example?

Redirecting is no option.

Mischa
  • 145
  • 1
  • 9

2 Answers2

1

My solution:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^([^.]+)\.domain.com
RewriteRule ([a-zA-Z0-9]+)/([a-zA-Z0-9]+) http://%1.$2.domain.com/$1 [P,L]
Mischa
  • 145
  • 1
  • 9
0

Please try this:

RewriteEngine On

RewriteBase /

RewriteRule ^(.*)/foobar/$  /$1 

I have tested it using http://htaccess.madewithlove.be/.

splattne
  • 28,508
  • 20
  • 98
  • 148
HariKrishnan
  • 109
  • 1
  • This does output the same URL. If I call http://de.domain.com/article1/foobar/ the Apache proxy should make a call on http://de.foobar.domain.com/article1/ – Mischa Aug 15 '13 at 08:57
  • @StinsonMaster I tested it again and it worked. Can you please check again? – HariKrishnan Aug 15 '13 at 09:11
  • The website I linked in this post http://htaccess.madewithlove.be/ sometimes seems to output the same url. Maybe you can check on your server. – HariKrishnan Aug 15 '13 at 09:15
  • I tried a little on my own. I got a good result with this: `RewriteCond %{HTTP_HOST} ^([^.]+)\.domain.com RewriteRule ([a-zA-Z0-9]+)/([a-zA-Z0-9]+) http://%1.$2.domain.com/$1 [L,R]` It's not working now, but the output url on http://htaccess.madewithlove.be/ is correct. – Mischa Aug 15 '13 at 09:17
  • Okay, I will try your config on my server. – Mischa Aug 15 '13 at 09:18
  • No, doesn't work on my server too. – Mischa Aug 15 '13 at 09:19
  • My solution is working now (had to remove the RewriteBase). But it makes a redirect because of [L,R]. I tried to use [P] for Proxy, but then he is redirecting me from `http://de.domain.com/article1/foobar/` to `http://de.domain.com/article1/` Any ideas? – Mischa Aug 15 '13 at 09:37
  • Okay, I think the redirect is because of other rules. I created another topic for this. – Mischa Aug 15 '13 at 12:08