【问题标题】:.htaccess add .html instead of slash(/) error.htaccess 添加 .html 而不是斜杠(/)错误
【发布时间】:2014-02-04 17:58:21
【问题描述】:

我将我的网站切换到 wordpress,但现在 url 链接以斜杠(/)而不是 .html 结尾,我不想丢失我的谷歌索引,所以在到处乱撞之后,我终于找到了解决方案.我创建了 .htaccess 规则,该规则将适用于每个页面。

我刚刚使用以下代码更新了根目录下的 .htaccess 文件:

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

现在任何像这样的 URL:/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

【问题讨论】:

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


【解决方案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

【讨论】:

  • 没有任何效果,我粘贴了您的代码,但仍然出现相同的错误。 :(
  • /whitepapers/ 是 WP 帖子/页面吗?
  • 非常感谢您。它现在正在工作。 :)
  • 我想投票,但需要 15 个声望。一旦获得超过 15 个声望,我一定会投票。
  • 太棒了!伟大的工作 anubhava,现在一切正常。 :)
猜你喜欢
  • 2012-01-12
  • 1970-01-01
  • 2014-04-27
  • 1970-01-01
  • 2012-08-03
  • 1970-01-01
  • 2017-08-09
  • 1970-01-01
  • 2012-03-25
相关资源
最近更新 更多