.htaccess 是否忽略由“%{HTTP\u HOST}”重写的COND?

.htaccess 是否忽略由“%{HTTP\u HOST}”重写的COND?,.htaccess,.htaccess,我有多个域指向服务器上的同一文件夹。php页面中的代码识别访问它的域,并显示每个域的不同内容 现在我希望www.domain-a.com\sitemap.xml打开/sitemap-a.xml,这样每个域都有自己的站点地图 我在.htaccess文件中使用以下规则: RewriteEngine On RewriteCond %{HTTP_HOST} ^.*domain-a\.com$ RewriteRule ^sitemap.xml$ sitemap-a.xml [NC] <IfModu

我有多个域指向服务器上的同一文件夹。php页面中的代码识别访问它的域,并显示每个域的不同内容

现在我希望
www.domain-a.com\sitemap.xml
打开
/sitemap-a.xml
,这样每个域都有自己的站点地图

我在
.htaccess
文件中使用以下规则:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*domain-a\.com$
RewriteRule ^sitemap.xml$ sitemap-a.xml [NC]
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>
    RewriteEngine On


    RewriteCond %{HTTP_HOST} ^.*domain-a\.com$
    RewriteRule ^sitemap.xml$ sitemap-a.xml [NC]

    # browser request: .php to non-php
    # https://stackoverflow.com/questions/13222850/redirect-php-urls-to-urls-without-extension
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
    RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

    # Now, rewrite any request to the wrong domain to use www.
    # [NC] is a case-insensitive match
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    # Don't put www. here. If it is already there it will be included, if not
    # the subsequent rule will catch it.
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
但是,如果我访问
www.domain-a.com\sitemap.xml
,则显示文件
/sitemap.xml
中的内容,而不是文件
sitemap-a.xml

重定向规则错误吗?如果是,我如何修复它

我用的是拉威尔。这是完整的
.htaccess
文件:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*domain-a\.com$
RewriteRule ^sitemap.xml$ sitemap-a.xml [NC]
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>
    RewriteEngine On


    RewriteCond %{HTTP_HOST} ^.*domain-a\.com$
    RewriteRule ^sitemap.xml$ sitemap-a.xml [NC]

    # browser request: .php to non-php
    # https://stackoverflow.com/questions/13222850/redirect-php-urls-to-urls-without-extension
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
    RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

    # Now, rewrite any request to the wrong domain to use www.
    # [NC] is a case-insensitive match
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    # Don't put www. here. If it is already there it will be included, if not
    # the subsequent rule will catch it.
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

选项-多视图-索引
重新启动发动机
重写cond%{HTTP_HOST}^.*domain-a\.com$
重写规则^sitemap.xml$sitemap-a.xml[NC]
#浏览器请求:.php到非php
# https://stackoverflow.com/questions/13222850/redirect-php-urls-to-urls-without-extension
重写cond%{THE_REQUEST}^[A-Z]{3,9}\/([^\]+)\.php
重写规则^/?(.*)\.php$/$1[L,R=301]
#现在,将任何请求重写到错误的域以使用www。
#[NC]是不区分大小写的匹配项
重写cond%{HTTP_HOST}^www\。[北卡罗来纳州]
重写规则。*https://www.%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
重写条件%{HTTPS}关闭
#首先重写到HTTPS:
#不要把www.放在这里。如果已经存在,将包括在内,如果没有
#随后的规则将捕获它。
重写规则。*https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
#句柄授权头
RewriteCond%{HTTP:Authorization}。
重写规则。*-[E=HTTP\U授权:%{HTTP:AUTHORIZATION}]
#如果不是文件夹,则重定向尾部斜杠。。。
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_URI}(+)/$
重写规则^1[L,R=301]
#处理前控制器。。。
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]

您能尝试一下这条规则吗就在
#Handle Authorization Header
行上方:

RewriteCond %{HTTP_HOST} (?:^|\.)domain-a\.com$ [NC]
RewriteRule ^sitemap\.xml$ /sitemap-a.xml [L,NC]

好啊是否
http://www.domain-a.com/sitemap-a.xml
从您的浏览器工作?@anubhava如果我尝试直接使用
http://www.domain-a.com/sitemap-a.xml
然后,
sitemap-a.xml
的内容如预期所示。我尝试了你的剪贴和上面的原始
#Handle Authorization Header
但是没有区别。我还清除了缓存。将其更改为
RewriteRule^sitemap\.xml$/sitemap-a.xml[L,NC,R]
查看浏览器中的URL是否更改或仍然没有重定向。我打开页面,然后按
strg
+
f5
清除缓存并刷新。我还试图删除
sitemap.xml
文件,但这会导致
404
错误。我取消了
RewriteCond
注释,因此我只有
RewriteRule^sitemap.xml$sitemap-a.xml[NC]
但仍然没有重定向。我也只尝试了
重写规则^sitemap\.xml$/sitemap-a.xml[L,NC]
,但仍然没有重定向。我在10个月前找到了这个。忘了吧。。很抱歉