Home Modrewrite for subdomains using .htaccess
Reply: 0

Modrewrite for subdomains using .htaccess

Laz Karimov
1#
Laz Karimov Published in 2017-11-14 22:33:49Z

I have tried the answers in this and this but always get redirection to example.com/any. I don't understand whether I should change both htaccess files or just the inner one.

I need to redirect any.example.com to example.com?subdomain=any

This is my file structure:

/folder1
/folder2
/folder3
/web/index.php
/web/.htaccess // inner htaccess
/.htaccess // outer htaccess

Outer .htaccess:

Options -Indexes

<IfModule mod_rewrite.c> 
  RewriteEngine on

  RewriteCond %{REQUEST_URI} !^public
  RewriteRule ^(.*)$ web/$1 [L] 
</IfModule>

# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>

# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]

Inner .htaccess:

RewriteEngine on

RewriteCond %{HTTP_HOST} !^example\.com$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
   Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<IfModule mod_expires.c>
   ExpiresActive On
   ExpiresByType image/jpg "access 1 year"
   ExpiresByType image/jpeg "access 1 year"
   ExpiresByType image/gif "access 1 year"
   ExpiresByType image/png "access 1 year"
   ExpiresByType text/css "access 1 month"
   ExpiresByType application/pdf "access 1 month"
   ExpiresByType application/javascript "access 1 week"
   ExpiresByType application/x-shockwave-flash "access 1 month"
   ExpiresByType image/x-icon "access 1 year"
   ExpiresDefault "access 2 days"
   ExpiresByType text/x-javascript "access plus 1 month"  
   ExpiresByType application/javascript "access plus 1 month"  
   ExpiresByType application/x-javascript "access plus 1 month"
</IfModule>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298601 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO