0

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.

2 Answers 2

1

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>  

ProxyPass / http://localhost:4000/
ProxyPassReverse / http://localhost:4000/
2
  • 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, 2011 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
    – user80776
    Jun 24, 2011 at 14:40
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .