在htaccess(wordpress)中将较长网址的规则重写为较短的网址

时间:2011-12-21 19:05:15

标签: wordpress .htaccess mod-rewrite

现在一个完整的网址是这样的:

website.com/en_us/multimedia/blogs/podcast/2011/08/post-title /

我想将上面的网址缩短到这个:

website.com/podcast/2011/08/post-title /

使用seo友好301重定向。

任何人都可以就如何实现这一目标提出建议?

谢谢!

我当前的.htaccess文件是这样的:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

1 个答案:

答案 0 :(得分:0)

要从website.com/en_us/multimedia/blogs/podcast/2011/08/post-title/重定向到website.com/podcast/2011/08/post-title/,请将以下内容添加到.htaccess文件中,然后再添加其他任何规则。

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} ^/en_us/multimedia/blogs/(.+)$ [NC]
RewriteRule . http://%{HTTP_HOST}/%1 [L,R=301]