skip to Main Content

Is it possible to use .htaccess to rewrite a sub domain?

Example:

http://fashion.example.com
shows the content of

http://example.com/index.php?name=fashion

<IfModule mod_rewrite.c>
# Turn on the rewrite engine
RewriteEngine  on

RewriteRule %{REQUEST_URI} ^(.*).example.com/$ index.php?name=$1

</IfModule>

2

Answers


  1. Assuming your subdomain is pointing to the same directory as your main domain, you can use something like the following :

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{HTTP_HOST} ^((?!www).+).example.com$
    RewriteRule ^(.+)/?$  /index.php?name=%1 [L]
    
    Login or Signup to reply.
  2. You may try this rule:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(?!www.)([^.]+).example.com$ [NC]
    RewriteRule ^ index.php?name=%1 [L,QSA]
    ``
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search