0

I would like to create admin.example.com, The URL router I am using is www.example.com/admin, I do not want to share the same login session. So I am thinking to use subdomain to solve this issue.

the admin actually is not a folder, it is a route from my route file. I am using Laravel 5.1.

What I want is when user access http://admin.example.com, it actually pointing to http://www.example.com/admin. However, user browser still showing http://admin.example.com

Any idea how do I able to in .htaccess?

Options +FollowSymLinks
RewriteEngine on

#Below is the code I added for the admin subdomain which doing a redirect, but I would like a mapping, not redirect
RewriteCond %{HTTP_HOST} ^admin.example.com
RewriteRule ^(.*)$ http://www.example.com/admin/$1 [L,NC,QSA]
#end of subdomain

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php [L]

Above code what it does is redirect, but what I want to a mapping.

vhost config file

<VirtualHost *:80>
        ServerName www.example.com
        DocumentRoot "C:\Bitnami\www\example.com\public"
</VirtualHost>

<VirtualHost *:80>
        ServerName admin.example.com
        DocumentRoot "C:\Bitnami\www\example.com\public"
</VirtualHost>
0

This is not possible with a .htaccess. You have to configure the VirtualHost directly in the Apache config.

You can combine your two VirtualHosts:

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias admin.example.com
    DocumentRoot "C:\Bitnami\www\example.com\public"
</VirtualHost>

Then you have to adapt your routing in Laravel. But this turns the question in a programming question, making it off topic for this site. I found some examples in a quick google search for laravel multiple domains, I suggest you do the same.

  • I had added the virtualhost on the subdomain, I had updated my question, the /admin actually is not a folder, it is a routing from a controller. – Shiro May 8 '17 at 9:30
  • Please add the virtualhost configuration to your question – Gerald Schneider May 8 '17 at 9:32
  • both is the set to the same folder, I had added – Shiro May 8 '17 at 9:36
  • I am not looking for multiple domain, I actually want ppl access admin.example.com is pointing to www.example.com/admin, maybe the question is proxy? – Shiro May 8 '17 at 9:42
  • Having two domains (normal and subdomain) IS multiple domains. Of course you can proxy apache to itself, you can also force redirects for all example.com/admin requests to admin.example.com, but both ways don't make much sense. The proper way to do this is to adapt the routing. – Gerald Schneider May 8 '17 at 9:46
0

It sounds like you're looking for a Reverse Proxy. Normally the easiest is to configure that from the VirtualHost entry:

<VirtualHost *:80>
        ServerName admin.example.com
        ProxyPass / http://www.example.com/admin/
        ProxyPassReverse / http://www.example.com/admin/
</VirtualHost>

But the ProxyPass directive is also valid in a .htaccess context.

  • It works for the homepage. When I access to admin.example.com, it redirect to admin.example.com/login. However, when I post the form, it keep redirect back the admin.example.com/login, When I view the source it is still showing example.com/admin/login I also tried added in routes.php below code:- \URL::forceRootUrl('admin.example.com/'); When I view the source it is showing http://admin.example.com/admin/login/ which is not correct, it should be http://admin.example.com/login/ – Shiro May 9 '17 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.