【问题标题】:htaccess disallowing icons to be visiblehtaccess 不允许图标可见
【发布时间】:2017-01-03 17:20:33
【问题描述】:

为了让.htaccess 允许fa 图标可见,我做了一些更改。

以前www.mywebsite.com fa 图标不可见。我在.htaccess 中添加了几行代码,它开始工作了。

<IfModule mod_headers.c>
<FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff)$">
    Header set Access-Control-Allow-Origin "http://www.mywebsite.com"
</FilesMatch>
</IfModule>
<IfModule mod_mime.c>
# Web fonts
AddType application/font-woff woff
AddType application/vnd.ms-fontobject eot

# Browsers usually ignore the font MIME types and sniff the content,
# however, Chrome shows a warning if other MIME types are used for the
# following fonts.
AddType application/x-font-ttf ttc ttf
AddType font/opentype otf

# Make SVGZ fonts work on iPad:
# https://twitter.com/FontSquirrel/status/14855840545
AddType     image/svg+xml svg svgz
AddEncoding gzip svgz

</IfModule>

现在,mywebsite.com(没有 www)不起作用。所以我加了

    Header set Access-Control-Allow-Origin "http://mywebsite.com"

这样

标头集 Access-Control-Allow-Origin "http://www.mywebsite.com" 标头集 Access-Control-Allow-Origin "http://mywebsite.com"

然后mywebsite.com 开始工作了。现在www.mywebsite.com 已经停止工作了。

我在我的网站上使用wordpress。我错过了什么?

编辑 我尝试根据各种论坛的建议添加 3 行,但最终却得到 500 Internal error。

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

我错过了什么,我需要将此代码放在某个 &lt;ifModule&gt; 块中吗?

【问题讨论】:

    标签: wordpress apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    您可能没有启用rewrite module。首先,将您的 htaccess 文件更新为如下所示:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{HTTP_HOST} !^www\.
        RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    </IfModule>
    
    <IfModule mod_headers.c>
        <FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff)$">
            Header set Access-Control-Allow-Origin "http://www.mywebsite.com"
        </FilesMatch>
    </IfModule>
    
    <IfModule mod_mime.c>
        # Web fonts
        AddType application/font-woff woff
        AddType application/vnd.ms-fontobject eot
    
        # Browsers usually ignore the font MIME types and sniff the content,
        # however, Chrome shows a warning if other MIME types are used for the
        # following fonts.
        AddType application/x-font-ttf ttc ttf
        AddType font/opentype otf
    
        # Make SVGZ fonts work on iPad:
        # https://twitter.com/FontSquirrel/status/14855840545
        AddType     image/svg+xml svg svgz
        AddEncoding gzip svgz
    </IfModule>
    

    然后,确保启用了重写模块:

    # Check if it's enabled:
    apachectl -M | grep rewrite
    
    # You might need sudo here:
    a2enmod rewrite
    
    # On platforms that a2enmod is not available, you need 
    # to open up your httpd.conf file and uncomment the line
    # that looks like this:
    LoadModule rewrite_module libexec/mod_rewrite.so
    

    【讨论】:

    • 我尝试将LoadModule 添加到httpd.conf,但没有找到。所以我检查了mod-enabled 文件夹。我在这里找到了 rewrite.load。我在这个文件中找到了LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so。出于某种原因,a2enmod rewrite 在 htaccess 更改后让网站正常工作。由于rewrite.load 已经在mod-enabled 文件夹中,模块不应该自动加载吗?
    • 每次重启机器时我都需要运行a2enmod rewrite 吗?
    • 抱歉,必须撤消接受。使用mywebsite.com时,网页浏览器在www.mywebsite.commywebsite.com之间不断切换并放弃。该网站没有加载,事实上它在没有任何图形的情况下加载了一段时间。
    • 抱歉,我的回答有误。我现在修好了。看看这是否适合你。如果您仍然进入重定向循环,则您的 htaccess 中必须有一些其他规则,此处未提及。不,您不需要每次都a2enmod rewrite。只需启用一次模块并重新启动服务器即可。
    猜你喜欢
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    • 2018-11-06
    • 1970-01-01
    • 2011-08-25
    • 2015-09-01
    • 1970-01-01
    相关资源
    最近更新 更多