How to configure url redirection with apache
This document (7014102) is provided subject to the disclaimer at the end of this document.
Environment
Situation
New Domain/DNS address. Need to configure old URL to redirect to new domain address.
Migrated domain's url address.
Resolution
- What is referred to below as the new domain is the domain URL that is the replacement or preferred address (www.new-domain.com).
- The new or secondary IP address is to be associated with the old or unpreferred domain address or URL (www.domain.com).
- 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. - 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. - 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.
- 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.
- Edit /etc/apache2/listen.conf:
- 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.
- Edit /etc/apache2/httpd.conf and append the following line to the <Directory /> section:
- 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
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com