2017-01-02 27 views
0

要獲得.htaccess允許fa圖標可見,我做了一些更改。htaccess禁止圖標可見

以前www.mywebsite.comfa圖標不可見。我給我的.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" 

喜歡這個

頭設置訪問控制允許來源「http://www.mywebsite.com」 頭設置訪問控制允許來源「http://mywebsite.com

而且mywebsite.com開始工作。現在www.mywebsite.com已停止工作。

我爲我的網站使用wordpress。我錯過了什麼?

編輯 我試圖根據各種論壇上的建議添加3行,但我最終得到500內部錯誤。

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

我錯過了什麼,我是否需要把這段代碼放在<ifModule>塊內?

回答

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 
+0

我試圖LoadModule'加上''到httpd.conf' ,但沒有找到它。所以我檢查了'mod-enabled'文件夾。我在這裏找到了rewrite.load。我在這個文件中找到了'LoadModule rewrite_module/usr/lib/apache2/modules/mod_rewrite.so'。出於某種原因,'a2enmod rewrite'在htaccess更改後使網站正常工作。模塊不應該自動加載,因爲'rewrite.load'已經在'mod-enabled'文件夾中了嗎? – Siddharth

+0

每當我重新啓動盒子時,是否需要運行'a2enmod rewrite'? – Siddharth

+0

抱歉,必須撤消接受。當使用'mywebsite.com'時,網頁瀏覽器不斷地在'www.mywebsite.com'和'mywebsite.com'之間切換並放棄。該網站不加載,事實上它的加載後一段時間沒有任何圖形。 – Siddharth