2014-10-01 213 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