We are building a website using MAMP.
You have now successfully set up a virtual host and displayed it in its subdomain (eg hoge.localhost).


<VirtualHost *: 80>
DocumentRoot "/ Applications/MAMP/htdocs/hoge /"
ServerName hoge.localhost

So, if you access the original address (eg http: // localhost/hoge /), how can you redirect it to a subdomain?

In httpd-vhost.conf,

<Directory />
Redirect/http: //hoge.localhost/

Try putting

RewriteEngine on
RewriteRule ^ localhost/hoge/$http: //hoge.localhost [L, R = 301]

I tried, but it was not redirected.

I'm sorry for the lack of knowledge, but I would appreciate it if someone could tell me.

  • Answer # 1

    A case of XAMPP, but if Apache httpd, the reasoning is the same, so is it helpful?

    Create a subdomain with Xampp-Qiita
    Set the subdomain to Apache localhost – ABC Blog

  • Answer # 2

    I haven't tested it.

    DocumentRoot "where there"
    ServerName localhost
    Redirect permanent/hoge http: //hoge.localhost

  • Answer # 3


    Assuming localhost is not a virtual domain, enter

    in httpd.conf
    Redirect permanent/hoge http: //hoge.localhost
    Try adding