How to set up url redirect in Apache on a linux server
There may be a need to change a url that people previously used and redirect it to a new url to access your web application.
On a linux server this can be done by modifying some apache configuration files in the Apache/conf directory
In httpd.conf (or ssl.conf if you have ssl enabled on your server) add the following line to include the mod_rewrite libraries:
include "../../Apache/Apache/conf/mod_rewrite.so"
Also include the mod_rewrite.conf file in httpd.conf (or ssl.conf if ssl is enabled):
include "../../Apache/Apache/conf/mod_rewrite.conf"
Create a new file in the Apache/conf directory with the name mod_rewrite.conf and add the following:
RewriteEngine on
RewriteLog /../../Apache/Apache/logs/rewrite.log
RewriteCond %{HTTP_HOST} ^oldurl:portNum$ [NC]
RewriteRule ^(.*)$ newurl:portNum$1 [R=301,L]
If there are multiple urls you want to redirect to the new url add the following into a file called mod_rewrite.conf:
RewriteEngine on
RewriteLog /../../Apache/Apache/logs/rewrite.log
RewriteCond %{HTTP_HOST} ^(url1|url2|url3|...urln):portNum$ [NC]
RewriteRule ^(.*)$ url-to-redirect-to:portNum$1 [R=301,L]
Once you have made the config changes restart the apache HTTP server. In oracle application server you do this by:
opmnctl stopproc ias-component=HTTP_Server
opmnctl startproc ias-component=HTTP_Server
ReplyDeleteI am glad to see that people are actually writing about this issue in such a smart way, showing us all different sides to it. Thanks for sharing, please keep it up.
XML connector