【问题标题】:www links wont redirect to a no-www 301 redirectwww 链接不会重定向到非 www 301 重定向
【发布时间】:2014-10-01 12:25:01
【问题描述】:

我刚刚为无 www 301 重定向添加了以下 .htaccess 规则:

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]

【问题讨论】:

  • 显示完整的.htaccess 文件并确保子文件夹中没有辅助文件。
  • 抱歉 :) 刚刚添加了 .htaccess 文件。

标签: wordpress apache .htaccess mod-rewrite redirect


【解决方案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 重定向,因此您的浏览器可能已被缓存,请使用其他浏览器以释放旧浏览器缓存并确保清除缓存。

【讨论】:

    猜你喜欢
    • 2018-05-01
    • 1970-01-01
    • 2014-04-09
    • 2017-05-03
    • 1970-01-01
    • 2018-10-19
    • 2019-11-29
    • 2021-09-13
    • 2019-08-12
    相关资源
    最近更新 更多