0

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>
Laz Karimov
  • 714
  • 10
  • 26
  • I don't see any place in these .htaccess where you try to actually match the pattern and redirect it. How do you expect it to work? What exactly did you try from the other answers? What exactly did not work? "Trying" does not mean merely copying and pasting. – Félix Adriyel Gagnon-Grenier Nov 14 '17 at 23:07
  • In question I've pasted the original .htaccess files, that are working without subdomains. I cannot paste each answer (not only accepted ones) I 've tried. They all, instead of showing the contect of example.com?subdomain=any, redirected to example.com?subdomain=any – Laz Karimov Nov 15 '17 at 08:09
  • As I said I dont get if it is enough to update my inner .htaccess, or maybe I should update config on my server... – Laz Karimov Nov 15 '17 at 08:12

0 Answers0