0

I want dynamically points sub domain to sub directory through htaccess without changing the urls and directory listing shows below.

|-- Test (Root Directory) <-- test.com redirects to this folder.
|-- index.php
|
|-- subdomain (Directory)
|
|---- abc (Directory) <-- abc.test.com redirects to this folder.
|------ index.php
|
|---- pqr (Directory) <-- pqr.test.com redirects to this folder.
|------ index.php
|
|---- xyz (Directory) <-- xyz.test.com redirects to this folder.
|------ index.php

I have applied following rewrite rule to points subdomain.

.htaccess file

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.test.com
RewriteRule (.*) http://test.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^test\.com $
RewriteCond %{REQUEST_URI} !^/subdomain/
RewriteRule (.*) /subdomain/$1

RewriteCond %{HTTP_HOST} ^(^.*)\.test.com
RewriteCond %{REQUEST_URI} !^/subdomain/
RewriteRule (.*) /subdomain/$1

I am not that much good in htaccess rewrite.

I have follow this subdomain on the fly

But I couldn't succeeded. Your suggestions are highly appreciated.

Thanks.

Community
  • 1
  • 1

1 Answers1

0

Hope this will help

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.test.com
RewriteRule (.*) http://test.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^\.]+)\.test\.com$ [NC]
RewriteRule ^(.*)$ http://test.com/subdomain/%1/$1 [L,NC,QSA]
ASR
  • 1,801
  • 5
  • 25
  • 33