Note that there are some explanatory texts on larger screens.

plurals
  1. PORoute subdomain to a directory in server
    primarykey
    data
    text
    <p>How is it possible to create a sub-domain in localhost. While using a windows machine I tried to edit the windows <code>host</code> file </p> <pre><code> 127.0.0.1 localhost 127.0.0.1/subdomain subdomain.localhost </code></pre> <p>to obtain something like this.</p> <pre><code>http://subdomain.localhost </code></pre> <p><br><strong>Update:</strong> First of all this question was asked without any context and this update is to improve the quality.<br><br> The following can be achieved by editing the vhosts file.</p> <p><em>vhosts:</em></p> <pre><code>&lt;VirtualHost *:80&gt; ServerAdmin webmaster@dummy-host.com DocumentRoot "C:/wamp/www/subdomain/" ServerName localhost ServerAlias subdomain.localhost ErrorLog "logs/error.log" CustomLog "logs/access.log" common &lt;/VirtualHost&gt; </code></pre> <p>And now on editing the hosts, the following can be solved.</p> <p><em>hosts</em></p> <pre><code>127.0.0.0 subdomain.localhost </code></pre> <p>Now I found a better example, by using the <code>RewriteRule</code> (that works with any subdomain, not just localhost)</p> <p>In the .htaccess file:</p> <pre><code>RewriteEngine on RewriteCond %{HTTP_HOST} ^sub.example.com RewriteRule ^(.*)$ http://example.com/subdomains/sub/$1 [L,NC,QSA] </code></pre> <p>For a more general rule we could replace the last two lines:</p> <pre><code>RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*)\.example\.com RewriteRule ^(.*)$ http://example.com/subdomains/%1/$1 [L,NC,QSA] </code></pre> <p>I am not a mod_rewrite expert, kindly help with the improvements and guides. <br> Thankyou.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload