1

i am going to redirect my domain to specific path.

thing that i want is

admin.example.com to admin.example.com/admin
partner.example.com to partner.example.com/partner

I need this two function in one .htaccess file. Thanks.

  • What should `admin.example.com/` redirect to? Do you have any existing directives in your `.htaccess` file? What have you tried so far that is not working? – MrWhite Oct 18 '16 at 17:06

1 Answers1

1

Assuming admin.example.com and partner.example.com point to the same place on the filesystem, then in the document root try the following (mod_rewrite directives) at the top of your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(admin|partner)\.example\.com$ [NC]
RewriteRule !^(admin|partner) http://%{HTTP_HOST}/%1 [R=302,L]

This will redirect just the two specific URLs as stated in your question, namely:

  • http://admin.example.com/ to http://admin.example.com/admin
  • http://partner.example.com/ to http://partner.example.com/partner

Change the 302 (temporary) redirect to 301 (permanent) when you are sure it is working OK - if this is to be a permanent redirect. (302s are easier for testing, since they won't be cached by the browser.)

MrWhite
  • 11,643
  • 4
  • 25
  • 40