• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

Apache redirect

 I would like to use apache to redirect pages to a new path.

E.g 1
OLD URL  =http://server1/mwiki/devwiki/index.php/page1.php
Redirect = http://server2/publicwiki/index.php/page1.php

E.g 2
OLD URL  =http://server1/mwiki/index.php/page3.php
Redirect = http://server2/privatewiki/index.php/page3.php

Thanks for the help
2 Solutions
On server1 in apache config or .htaccess

RewriteBase /
RewriteRule ^mwiki/devwiki/index.php/page([0-9]*).php http://server2/publicwiki/index.php/page$1.php [R=301,L]

You can use the Redirect directive in your Apache configuration. For example on server1 use:

Redirect /mwiki/devwiki/index.php/page1.php http://server2/publicwiki/index.php/page1.php

Redirect /mwiki/index.php/page3.php http://server2.privatewiki/index.php/page3.php

You may not want to redirect just a specific file like that but rather the whole directory. If this is the case, just omit the file names. The redirect will take the additional information in the original URL and append it to the final URL automatically.

Also, if you want it to be a permanent redirect (http response 301), put the word permanent between the Redirect directive and the original url. The defaults is a temporary redirect (http response 302).

You can use this in the main httpd.conf, virtual host context, directory context, or .htaccess file. This also requires mod_alias to be loaded and I'm assuming you're on Apache 2.2. For additional information, see the Apache documentation:


There are other ways of doing redirects also. This may or may not be the best solution for you depending on what you are trying to achieve. Just for basic redirection it should fit the bill.

Hope this helps!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now