How to configure url redirection with apache

This document (7014102) is provided subject to the disclaimer at the end of this document.

Environment

SUSE Linux Enterprise Server

Situation

How to configure apache for url redirection from http://www.domain.com to http://www.new-domain.com
New Domain/DNS address. Need to configure old URL to redirect to new domain address.
Migrated domain's url address.

Resolution

Here are a couple definitions that should be understood before proceeding:

  1. What is referred to below as the new domain is the domain URL that is the replacement or preferred address (www.new-domain.com).
  2. The new or secondary IP address is to be associated with the old or unpreferred domain address or URL (www.domain.com).

In the example below, any requests that come in to www.domain.com are forwarded to www.new-domain.com:

  1. Add a secondary IP address to the server. YaST | Network Settings.
    Note: This presumes both URLs or domains resolve to the same ip-address or server. Separate IP address are needed to manage proper url redirection on the same server.
  2. Configure DNS to point this new IP address to www.domain.com (the unpreferred url).
    Note: When users access www.domain.com, they are directed to this new IP address, which in the following steps will be handled by a new instance of apache that will redirect the request to the preferred domain address or URL www.new-domain.com.
  3. Install apache on the server:
    • YaST | Software Management 
    • Select Patterns. From the left panel under Primary Functions, select Web and LAMP Server.
    • Check apache2 and select Accept.
    • Proceed with Installation and Configuration.
      Note: If possible, configure apache to to Listen only with the new network address from Step 1 and on port 80; however, this is covered manually in the next Step.
  4. In order to receive these requests, configure apache to listen on the new IP address, port 80 only:
    Note: If this is already configured from Step 3, you can skip this section. The goal is to get apache to listen on the new IP address only (the one created in Step 1), not interfering with the current IP address already associated with www.new-domain.com.
    • Edit /etc/apache2/listen.conf:
      • Replace Listen 80 with Listen <ipAddress>:80
      • For example: Listen 151.155.215.91:80
        Note: This is the new IP address used in Step 1.
    • Save and Close file.
  5. Configure apache for URL redirection:
    Note: This redirects any incoming requests to this new apache instance (http://www.domain.com) to the http://www.new-domain.com. We use a 301 redirect because it is a Moved Permanently redirection. Google recommends using a 301 redirect to change the URL as it is shown in search engine results [1]. If this is not a permanent domain redirection, but rather a temporary one, consider using a 302 redirect.
    • Edit /etc/apache2/httpd.conf and append the following line to the <Directory /> section:
      RedirectMatch 301 ^(.*)$ http://www.new-domain.com
    • The <Directory /> section should now appear as below:
      <Directory />
          Options None
          AllowOverride None
          Order deny,allow
          Deny from all
         
      RedirectMatch 301 ^(.*)$ http://www.new-domain.com
      </Directory>
    • Save and Close the file.
  6. Restart apache:
    rcapache2 restart

Cause


Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.

  • Document ID:7014102
  • Creation Date: 12-Nov-2013
  • Modified Date:03-Mar-2020
    • SUSE Linux Enterprise Server

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback@suse.com

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

Join Our Community

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.


SUSE Customer Support Quick Reference Guide SUSE Technical Support Handbook Update Advisories
Support FAQ

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.

Go to Customer Center