skip to Main Content

I want so that when im in http://localhost/example/category it allows me to have a subdomain that is dynamic like user1.localhost/example/category, user2.localhost/example/category, user3.localhost/example/category etc…

I got it working with the index from localhost but i want it to work when its in the category webpage and only in that webpage I would appreciate if someone could help me underneath is what i tried to do

httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/wamp64/www"
    ServerName localhost
    ServerAlias *.localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
    <Directory "C:/wamp64/www">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

hosts


127.0.0.1 localhost
127.0.0.1 *.localhost
::1 localhost

3

Answers


  1. Chosen as BEST ANSWER
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).example.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/storeify/category/([0-9]+)$
    RewriteRule ^storeify/category/([0-9]+)$ /storeify/category/ [L,QSA]
    

  2. You can check whether you are on an alias domain and if so, whether it’s the category page:

    <if "%{SERVER_NAME} != 'localhost'">
       RewriteCond %{REQUEST_URI} !^/(category)/ [NC]
       RewriteRule . /some/path/you/want.html  [L]
    </if>
    

    (untested)

    Login or Signup to reply.
  3. Wildcards are not supported in the hosts file. You may try manually adding multiple entries in the hosts file in order to test whether you have your webserver configured correctly, for example:

    user1.localhost 127.0.0.1
    user2.localhost 127.0.0.1
    ...
    

    Once you are happy that your webserver is configured correctly, your best route to getting wildcard domains working would probably be a local DNS resolver. If you’re on Ubuntu, maybe you can achieve this with resolvconf…

    In regards to only wanting it to work on the category webpage, that comes down to the program you are writing. You could probably do some blocking in .htaccess itself, however you are already specifically going to have to handle multiple domains within your web application, so I would suggest you program these restrictions in there as well.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search