【问题标题】:.htaccess 301 redirect from /?p=blahblahblah.htaccess 301 从 /?p=blahblahblah 重定向
【发布时间】:2017-09-17 11:04:28
【问题描述】:

我正在尝试在我转换为 WordPress 的网站的 .htaccess 文件中设置 301 重定向。

旧网站的网址如下所示

http://www.example.com/?p=about
http://www.example.com/?p=contact-us

我尝试过的重写规则如下,但没有一个工作。

Redirect 301 /?p=about /about/
Redirect 301 /?p=contact-us /contact-us/

Redirect 301 /?p=about http://www.example.com/about/
Redirect 301 /?p=contact-us http://www.example.com/contact-us/

Redirect 301 /\?p=about /about/
Redirect 301 /\?p=contact-us /contact-us/

Redirect 301 /\?p=about http://www.example.com/about/
Redirect 301 /\?p=contact-us http://www.example.com/contact-us/

似乎 WordPress 重写规则首先启动,即使我在 WordPress 重定向规则之上有 301 重定向。显示的页面是博客滚动页面,显示“Nothing Found”,因为我没有帖子。

有没有办法让这些重定向工作?

【问题讨论】:

  • 您是否尝试过在浏览器中打开私人标签并查看重定向是否有效(或尝试使用您之前从未访问过该网站的浏览器)? 301 重定向是永久性的,大多数浏览器都会对其进行缓存,直到明确清除为止。
  • 刚刚试过。还是不行。

标签: wordpress apache .htaccess


【解决方案1】:

您是对的:如果将重定向规则放在 WordPress 规则之后,则不会考虑重定向规则。这一行:

RewriteRule . /index.php [L]

将重定向所有内容,最后的 le [L] 表示这是最后一条规则。

这是你应该把你的.htaccess文件放进去吗:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# old site redirections
RewriteRule /?p=about /about/ [L,R=301]
RewriteRule /?p=contact-us /contact-us/ [L,R=301]

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

# END WordPress

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-01
    • 2011-01-03
    • 2012-03-10
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多