Apache redirect

Posted on 2011-05-10
Last Modified: 2012-05-11
 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
Question by:SiemensSEN
    LVL 4

    Assisted Solution

    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]
    LVL 1

    Accepted Solution


    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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
    It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now