1

I have following structure in my root directory

/
/-site1
/-site2
.
.
.-site-n

I want to have site1.example.com to use site1 folder, site2.example.com to use site2 folder and so on. I want to achieve this with htaccess.I also want to redirect to 404 page if a directory (sitex) not exist. Please provide me suggestion to write htaccess file and also mention where should I need to put it.

Sunil Kumar
  • 129
  • 1
  • 7
  • 1
    Please show us, what you have already done in your .htaccess file – trpx Jul 14 '17 at 06:51
  • 7
    Possible duplicate of [.htaccess rewrite subdomain to directory](https://stackoverflow.com/questions/10642426/htaccess-rewrite-subdomain-to-directory) – Fred Gandt Jul 14 '17 at 06:53
  • I am using this: - RewriteEngine On Rewritemap lowercase int:tolowerRewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC] RewriteCond %{DOCUMENT_ROOT}/%1 !-d RewriteRule ^ - [L,R=404] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC] RewriteCond %{DOCUMENT_ROOT}/%1 -d RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_FILENAME} -f [OR] ##RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_FILENAME} -l [OR] RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_FILENAME} -d RewriteRule ^(.*)$ /%1/$1 [L] – Sunil Kumar Jul 14 '17 at 07:37

1 Answers1

0

If this helps - tracing out the comments and from the reference

<IfModule mod_rewrite.c>    
    RewriteEngine on 
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteCond %{REQUEST_URI} !^/%1/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /%1/$1 

    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^$ %1/index.php [L] 
</IfModule>
Yellow and Red
  • 695
  • 9
  • 31