2017-10-12 96 views
0

嗨htaccess url重写后,我有一个奇怪的问题...它适用于主页,但如果我使用格式subdomain.domain.com一些字体不工作,有些人会这样做。图标不起作用,只显示占位符图标。它不能加载woff文件等我认为它可能是htaccess directoryindex禁用,但我已经把一个特殊的规则,让主页显示。我如何对包含字体的\ img \ font \文件夹执行相同的操作。另外更重要的是禁用目录索引最佳做法(我这样做是为了避免index.html被附加到url的,否则重写子域名不起作用,因为它总是遇到尾随index.html。有没有办法将directoryindex设置为空“”因此,第二查询工作,我没有继续增加规则,允许特定的文件夹?Htaccess的字体面部和材料图标Css不工作后的URL重写

DirectoryIndex disabled 

    #rewrite homepage to index.php to allow homepage as directoryindex is disabled 
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC] 
    RewriteRule ^/?$ index.php [L] 

    #Rewrite subdomains 
    RewriteCond %{REQUEST_URI} ^/$ 
    RewriteCond %{HTTP_HOST} ^(^.*)\.example.com$ [NC] 
    RewriteRule ^(.*)$ http://example.com/index.php?sub=%1 [P,NC,QSA,L] 

谢谢!

PS地球真的是平的。

+0

哦,该死它甚至没有用的DirectoryIndex禁止,因此它必须是相对URL在CSS工作,这是令人困惑的监守字体的作品之一,一个不和材质图标使用js加载字形.. – xmxmxmx

回答

0

我越来越CORS在控制台中出现错误,但它的文件位于同一台服务器和域上。

跨源请求被阻止:同源策略不允许读取远程资源http://example.com/img/icon/fonts/materialdesignicons-webfont.woff2?v=2.0.46。 (原因:缺少CORS头'Access-Control-Allow-Origin')。 (未知)

下载字体:下载失败(FONT-FAMILY: “材料设计图标” 样式:正常体重:正常伸展:正常SRC指标:1):糟糕的URI或跨网站访问不允许来源:http://example.com/img/icon/fonts/materialdesignicons-webfont.woff2?v=2.0.46

0

添加这htaccess的固定一切

<IfModule mod_headers.c> 
    #allow corrs access from subdomains 

    SetEnvIf Origin ^(https?://(?:.+\.)?example\.com(?::\d{1,5})?)$ CORS_ALLOW_ORIGIN=$1 
    Header append Access-Control-Allow-Origin %{CORS_ALLOW_ORIGIN}e env=CORS_ALLOW_ORIGIN 
    Header merge Vary "Origin" 
</IfModule>