.htaccess添加.html而不是斜杠(/)错误

时间:2014-02-04 17:58:22

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

我将我的网站切换到wordpress,但现在url链接以斜杠(/)而不是.html结束,我不想丢失我的谷歌索引所以在这里和那里敲打我的头后,我终于找到了解决方案。我创建了.htaccess规则,可以为每个页面全局工作。

我刚用root下面的代码更新了.htaccess文件:

RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule ^(.*)\/$ $1.html [R]
RewriteRule ^(.*).html$ index.php/$1 [L]

现在任何这样的网址:/ features / cart /都会自动转发到/features/cart.html 一切都工作正常,但现在我在那些已经有.html扩展名的页面上收到404错误。 请尽快建议,因为我正在失去索引和关键字排名。

以下是.htaccess文件的实际代码:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.php !-f

# Rewrite rule for appending .html
RewriteRule ^(.*)\/$ $1.html [R]
RewriteRule ^(.*).html$ index.php/$1 [L]



redirect 301 /about_us.html /about.html
redirect 301 /about/ /about.html

</IfModule>

# END WordPress

网站名称:dailydealbuilder.com

1 个答案:

答案 0 :(得分:1)

尝试重新排序您的规则:

Redirect 301 /about_us.html /about.html
Redirect 301 /about/ /about.html

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.php !-f
# Rewrite rule for appending .html
RewriteRule ^(.+?)/$ $1.html [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^(.+?)\.html$ index.php/$1 [L]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

</IfModule>
# END WordPress