How to redirect a user using Apache Rewrite to a fully qualified domain name?

I am really new to apache mod_rewrite module. I have a page with a name http://abcon my corporate intranet. I want users to be redirected to http://abc.somecompanyname.comwhen they type http://abcin a URL string. Can someone provide and give an example or point me in the right direction.

I believe this should be a fairly simple question to answer. Thank you all for you.

-Mark

+5
source share
3 answers

You could make VirtualHost's definition simple, like on this one, on a server processing requests for abc:

<VirtualHost *:80>
    ServerName abc
    RewriteEngine on
    RewriteRule ^/(.*)$ http://abc.somecompanyname.com/$1 [R,L]
</VirtualHost>
+4
source

Apache 2.4:

mod_rewrite, Redirect, .

<VirtualHost *:80>
  ServerName undesired.example.com
  ServerAlias example.com notthis.example.com

  Redirect / http://www.example.com/
</VirtualHost>

<VirtualHost *:80>
  ServerName www.example.com
</VirtualHost>

, . - , "" .

+4

I found advice in Apache2. The URL rewriting guide worked better.

I ended up with:

RewriteEngine on
RewriteCond %{HTTP_HOST}   !^foo\.bar\.com [NC]
RewriteCond %{HTTP_HOST}   !^$ 
RewriteRule ^/(.*)         http://foo.bar.com/$1 [L,R]

The string "RewriteEngine on" was not included in the Apache2 example. Perhaps this is usually the default, but in my case I needed to add it.

+1
source

All Articles