我正在尝试将所有现有网址重定向到新的略微简化的网址结构,并希望保留已在google / bing上编入索引的现有链接。
帖子的当前网址如下所示 / blog / post / some-random-post-here 新帖子网址几乎相同,但不再包含 / post / 。而是 / blog / some-random-post-here
我为新网址创建了一个新的htaccess规则。截至目前,两个版本的网址都有效。但是我希望保留一份副本用于SEO原因。这是在一个从头开始的博客(这不是WordPress或其他博客软件)
以下是我的htaccess中旧网址和新网址的重写规则。
**OLD URL:** RewriteRule ^post/([^/]+)/$ index.php?controller=post&action=view&post=$1 [L]
------------------------------------------------------------------------
**NEW URL:** RewriteRule ^([^/]+)/$ index.php?controller=post&action=view&post=$1 [L]
为了使301永久重定向到新的url结构,我需要添加到OLD URL结构中? OLD和NEW重写规则仍然有效。但我宁愿将旧规则改为新网址。
提前谢谢。
答案 0 :(得分:0)
您可以使用RedirectMatch指令进行此网址重定向,这很容易。
尝试:
RedirectMatch 301 ^/blog/post/(.*)$ http://domain.com/blog/$1
或尝试mod_rewrite删除查询字符串
RewriteEngine on
RewriteRule ^blog/post/(.*)$ http://example.com/blog/$1? [NC,R,L]
最后清空问号?非常重要,因为它会从网址中丢弃原始查询字符串。
将301重定向
http://example.com/blog/post/foo
到
http://example.com/blog/foo