重写htaccess擦除字符串

时间:2013-09-23 15:53:39

标签: php wordpress .htaccess redirect mod-rewrite

我想从网址中删除字符串:

http://www.example.com/wp/post-id/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+my-feed-example+%28feedexample.com+escape+this+string+now%29&utm_content=FeedBurner

要:

http://www.example.com/test/post-number/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+my-feed-example+&utm_content=FeedBurner

我想删除这个字符串:

%28feedexample.com+escape+this+string+now%29

post-id超过1000(帖子),因此我无法手动重定向(301)我的所有链接。

有可能吗?怎么样?

1 个答案:

答案 0 :(得分:0)

启用mod_rewrite.htaccesshttpd.conf,然后将此代码放在.htaccess DOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(wp/post-id/\?.*?utm_campaign=.*?)\%28feedexample\.com\+escape\+this\+string\+now\%29([^\s]+)\s [NC]
RewriteRule ^ /%1%2 [L,R=301,NE]