Search code examples
.htaccesswebsubdomain

.htaccess: rewrite the adress in adress bar from subdomain to full path


I want to achieve this:

If you visit the subdomain of a website, e.g.

project.website.com

I want it to be replaced automatically in the address bar to

https://website.com/project-directory

-> So the subdomain should directly lead to the full directory path and also show that full path in the address bar.

How do I achieve this using the .htaccess file? Or is another way better? Thanks for helping!


Solution

  • Found this answer to a similar question:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^subdomain\.yourdomain\.com
    RewriteRule ^(.*)$ http://www\.yourdomain\.com/subdomain/$1 [L]
    

    found it here: https://stackoverflow.com/a/13637970/17799753