Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

rewrite a subdomain to a path using Apache?


I've been asked if I can rewrite an address using Apache 2.2

I'm trying to get and of these
members|intranet|email to become the path after a preset domain, whatever http or https method used initially should also follow through


http://members.bbb.co.uk should re-write to http://www.bbb.co.uk/members
https://members.bbb.co.uk should re-write to https://www.bbb.co.uk/members

and so on

I think I need something like this but not really sure what I am doing here:
#RewriteRule ^(members|intranet|email)(?:/(.*))?$ https://aa.bbbbbbb.co.uk/$1 [P]

Thanks in advance
Neil Thompson
Neil Thompson
  • 2
1 Solution
Dave BaldwinFixer of ProblemsCommented:
Don't you have that backwards?  The first item is what is seen in the browser and the second item is where it goes on the server.

http://www.bbb.co.uk/members should re-write to http://members.bbb.co.uk
https://www.bbb.co.uk/members should re-write to https://members.bbb.co.uk
Dave BaldwinFixer of ProblemsCommented:
On my site it looks like this.
RewriteEngine on  

RewriteCond %{HTTPS} !=on
RewriteRule ^members  http://members.bbb.co.uk/

RewriteCond %{HTTPS} =on
RewriteRule ^members  https://members.bbb.co.uk/

Open in new window

Try this
RewriteEngine on
RewriteCond %{HTTPS}:s (on:(s)|off:s)
RewriteCond %{HTTP_HOST} ^(email|members|internet)\. [NC]
RewriteRule (.*) http%1://www.site.com/%2 [R=301,L]

Open in new window

Neil ThompsonSenior Systems DeveloperAuthor Commented:
Many thanks , spot on

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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