Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have two domains - domain.com and forum.domain.com that points to the same directory.

I'd like redirect all request from forum.domain.com to domain.com (for example: forum.domain.com/foo to domain.com/forum/foo) without changing address in addres bar (hidden redirect).

I wrote something like this and put it into .htaccess file:

Options +FollowSymlinks
RewriteEngine on   

RewriteCond %{HTTP_HOST} ^forum\.example\.net$
RewriteRule (.*) http://example.com/forum/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-s [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+) index.php/$1 [L]

That works only if I add Redirect directive:

RewriteRule (.*) http://example.com/forum/$1 [R,L]

But it changes previous address in address bar.

EDIT:

Ok, let's make it simple. I added those two lines at the end of the c:\windows\system32\drivers\etc\hosts on my local computer:

127.0.0.3   foo.net
127.0.0.3   forum.foo.net

Now, I created two virtual hosts:

<VirtualHost foo.net:80>
    ServerAdmin admin@admin.com
    ServerName foo.net
DocumentRoot "C:/usr/src/foo"
</VirtualHost>

<VirtualHost forum.foo.net:80>
    ServerAdmin admin@admin.com
    ServerName forum.foo.net
DocumentRoot "C:/usr/src/foo"
</VirtualHost>

..and directory called "foo", where i put two files: .htaccess and index.php.

Index.php:

<?php

echo $_SERVER['PATH_INFO'];
?>

.htaccess:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^forum\.foo\.net$
RewriteCond %{REQUEST_URI} !^/forum/
RewriteCond %{REQUEST_FILENAME} !-s [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ /index.php/forum/$1 [L]

RewriteCond %{HTTP_HOST} !^forum\.foo\.net$
RewriteCond %{REQUEST_FILENAME} !-s [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+) index.php/$1 [L]

When I type address http://forum.foo.net/test in address bar, it displays /forum/test which is good. http://foo.net/a/b/c shows /a/b/c which is good. But! http://forum.foo.net/ displays empty value (should display /forum).

share|improve this question
    
domain.com and forum.domain.com were two seperate virtual hosts, but not anymore :) They are the same IP addres - ServerAlias. However, I'd my old links work as usual without redirecting (without HTTP header 301) –  Bald Oct 11 '10 at 14:52

1 Answer 1

Enable mod_proxy and use the P flag instead.

share|improve this answer
    
Hmm, does not work. Could you give me an example? –  Bald Oct 14 '10 at 15:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.