Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 如果子域不存在,则htaccess重写_.htaccess - Fatal编程技术网

.htaccess 如果子域不存在,则htaccess重写

.htaccess 如果子域不存在,则htaccess重写,.htaccess,.htaccess,我创建了一个子域用作无炊事域,它类似于cdn.domain.com 在主网站上我有www.domain.com。无论我叫它什么,它都是www.cdn.domain.com。我正在使用cdn.domain.com调用图像等 在这里您可以看到实际的htaccess设置 <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] RewriteRule (.*?)i

我创建了一个子域用作无炊事域,它类似于cdn.domain.com

在主网站上我有www.domain.com。无论我叫它什么,它都是www.cdn.domain.com。我正在使用cdn.domain.com调用图像等

在这里您可以看到实际的htaccess设置

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond $1 !^(index\.php|images|robots|public|sitemap.xml|favicon.ico|\.txt|\.html)
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]
</IfModule>

重新启动发动机
RewriteCond%{THE_REQUEST}^GET.*index\.php[NC]
重写规则(.*)索引\.php/*(.*)/$1$2[R=301,NE,L]
#首先将任何请求重写到错误的域以使用正确的域(此处为www.)
重写cond%{HTTP_HOST}^www\。
重写规则^(.*)$https://www.%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
#现在,重写为HTTPS:
重写条件%{HTTPS}关闭
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
1美元^(索引\.php | images | robots | public | sitemap.xml | favicon.ico | \.txt | \.html)
重写规则^(.*)$/index.php?/$1[L]
RewriteCond%{HTTP_USER_AGENT}libwww perl.*
重写规则。*?[F,L]

如何在不影响对主域设置的任何更改的情况下获取信息?

我想您正在寻找以下信息:

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
您的htaccess现在看起来是这样的:

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond $1 !^(index\.php|images|robots|public|sitemap.xml|favicon.ico|\.txt|\.html)
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]
</IfModule>

重新启动发动机
RewriteCond%{THE_REQUEST}^GET.*index\.php[NC]
重写规则(.*)索引\.php/*(.*)/$1$2[R=301,NE,L]
#首先将任何请求重写到错误的域以使用正确的域(此处为www.)
重写条件%{HTTP\u HOST}^[^.]+\.[^.]+$
重写规则^(.*)$http://www.%{HTTP_HOST}/$1[L,R=301]
#现在,重写为HTTPS:
重写条件%{HTTPS}关闭
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
1美元^(索引\.php | images | robots | public | sitemap.xml | favicon.ico | \.txt | \.html)
重写规则^(.*)$/index.php?/$1[L]
RewriteCond%{HTTP_USER_AGENT}libwww perl.*
重写规则。*?[F,L]

www添加到第二个块中,您应该添加另一个
RewriteCond%{HTTP\u HOST}!cdn.domain.com
在那里。你可以在这里测试