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

I would like to set up multiple redirects using apache but am completely stumped as to how to do it?

I have a nodejs instance which serves up my home page running on my server on port 4000. It can be accessed from the server at localhost:4000 (port 4000 is not open to external access).

I have a blog that is a wordpress instance.

The blog resides at mysite.com/blog

So. I would like all requests to mysite.com/blog/xxxxx to be redirected to the wordpress instance, and all other requests (e.g. mysite.com/xxxx/yyyy) to be redirected to my node instance at http://localhost:4000/xxxxx/yyyy

My config file looks like this

  9 <VirtualHost *:80>                                                          
 10                                                                             
 11   # Admin email, Server Name (domain name) and any aliases                  
 12   ServerAdmin xxxxx                                           
 13   ServerName  xxxxx                                                   
 14   ServerAlias xxxxx                                                       
 15                                                                             
 16                                                                             
 17   # Index file and Document Root (where the public files are located)       
 18   DirectoryIndex index.html index.php                                       
 19   DocumentRoot /xxx/xxx/public_html/xxx/public  

.....

 26     <Location />                                                            
            ?? What goes here?
 31     </Location>

......

 33     <Location /blog>                                                        
 34         RewriteEngine On                                                    
 35         RewriteBase /blog/                                                  
 36         RewriteRule ^index\.php$ - [L]                                      
 37         RewriteCond %{REQUEST_FILENAME} !-f                                 
 38         RewriteCond %{REQUEST_FILENAME} !-d                                 
 39         RewriteRule . /blog/index.php [L]                                   
 40     </Location>  

I have tried setting up rewrite rules and proxies but either the blog doesnt work, or the home page does not work.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I believe (though I may be mistaken) Apache processes <Location> tags in order, so if you want to map a sub-folder of /blog you'd need to do

<Location /blog>                                                        
    RewriteEngine On                                                    
    RewriteBase /blog/                                                  
    RewriteRule ^index\.php$ - [L]                                      
    RewriteCond %{REQUEST_FILENAME} !-f                                 
    RewriteCond %{REQUEST_FILENAME} !-d                                 
    RewriteRule . /blog/index.php [L]                                   
</Location>  

<Location />                                                        
    ProxyPass / http://localhost:4000/
    ProxyPassReverse / http://localhost:4000/
</Location>  
share|improve this answer
    
This answer is based on zero research... You cannot use ProxyPass with a location, within a location tag.... you wont even be able to restart apache with this in your configuration file –  mrwooster Jun 24 '11 at 11:15
    
@mrwooster I'm doing it from memory, yes you are correct you need to remove the ProxyPass tags from the location block but the rule should still apply I.E. put the ProxyPass tags after the initial /blog location, the first block will catch and process the directory and the proxy pass lines will catch anything else –  sam Jun 24 '11 at 14:40

try to put the following lines after your <Location /blog>...</Location> part:

ProxyPass / http://localhost:4000/
ProxyPassReverse / http://localhost:4000/

I'm not quite sure anymore how matching works between location and proxy directives. But when it comes to proxy directives only they work in a in-order,first-match principle.

share|improve this answer

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.