• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

.htaccess - Need to send non-full-url to full url. (intranet -> intranet.hostname.com)

Hi all.
Using Apache and Joomla for our corp. intranet.

The intranet is accessed by a variety af url's
http://intranet http://intranet2 http://trgnet http://intranet.ourhostname.com

I want to use .htaccess to redirect all access to the full url - http://intranet.company.com

A working example would be great :-)

1 Solution
You could do something like :
Redirect / http://intranet.company.com

You have to be careful if the new webserver is on the same box in case you get caught in a loop.

This also means the web server must be up to resolve these names and server the redirection.

A better way would be to NOT do this in .htaccess but do it all in the DNS server then when they request a page they will end up on the right server without hitting the other web server.
Something like :

intranet        IN      CNAME   intranet.company.com.
intranet2      IN      CNAME   intranet.company.com.
trgnet          IN      CNAME   intranet.company.com.
intranet.ourhostname.com       IN      CNAME   intranet.company.com.

You can check the http host with mod_rewrite only (an other approach would be to use a separate virtual host for all non-full urls and place  Redirect statement there.)

Make sure apache's module  mod_rewrite is loaded and your webserver is configured that you're allowed to use such directives in a .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} !=intranet.company.com
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^ http://intranet.company.com%{REQUEST_URI} [R=301,L]

Open in new window

trg_dkAuthor Commented:
Thanks for your reply - works like a charm
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now