2014-10-01 34 views
0

我剛添加了以下.htaccess規則無WWW 301重定向:WWW鏈接不會重定向到一個沒有301重定向

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

我的域名www.example.net現在完全重定向到example.net,但是當我訪問我的任何與www前綴www.example.net/2014/03/some-article/的文章,重定向不會發生。我看到一個破碎的頁面。

這裏有什麼問題,有什麼解決方案來解決它?

.htaccess

# BEGIN All In One WP Security 
#AIOWPS_BASIC_HTACCESS_RULES_START 
<Files .htaccess> 
order allow,deny 
deny from all 
</Files> 
ServerSignature Off 
LimitRequestBody 10240000 
<Files wp-config.php> 
order allow,deny 
deny from all 
</Files> 
#AIOWPS_BASIC_HTACCESS_RULES_END 
# END All In One WP Security 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 
RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
+0

顯示完整的'.htaccess'文件並確保子文件夾內沒有輔助文件。 – Prix 2014-10-01 12:27:11

+0

對不起:)剛添加'.htaccess'文件。 – 2014-10-01 12:28:39

回答

1

您的問題可能與你的規則被放置,因爲您的重定向是最後它可能不會被觸發的順序,由於先前定義的規則。

既然你必須從改變你的文件:

# BEGIN All In One WP Security 
#AIOWPS_BASIC_HTACCESS_RULES_START 
<Files .htaccess> 
order allow,deny 
deny from all 
</Files> 
ServerSignature Off 
LimitRequestBody 10240000 
<Files wp-config.php> 
order allow,deny 
deny from all 
</Files> 
#AIOWPS_BASIC_HTACCESS_RULES_END 
# END All In One WP Security 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 
RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

要:

# BEGIN All In One WP Security 
#AIOWPS_BASIC_HTACCESS_RULES_START 
<Files .htaccess> 
order allow,deny 
deny from all 
</Files> 
ServerSignature Off 
LimitRequestBody 10240000 
<Files wp-config.php> 
order allow,deny 
deny from all 
</Files> 
#AIOWPS_BASIC_HTACCESS_RULES_END 
# END All In One WP Security 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

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

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 

在心裏也讓你一直在使用301重定向,以便您的瀏覽器可能會被緩存,請使用不同的瀏覽器來釋放舊的瀏覽器緩存,並確保清除緩存。

+0

謝謝:)現在它工作... – 2014-10-01 12:43:31

+0

:)簡單不是它 – Prix 2014-10-01 12:46:51

+0

哈哈...是的;) – 2014-10-01 13:00:17