使用.htaccess的子域的Modrewrite

时间:2017-11-14 22:33:49

标签: .htaccess mod-rewrite

我在thisthis中尝试过这些答案,但总是会重定向到example.com/any。我不明白我是应该更改htaccess文件还是仅更改内部文件。

我需要将any.example.com重定向到example.com?subdomain=any

这是我的文件结构:

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

外面.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]

内心.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>

0 个答案:

没有答案