开发者

Redirect hundreds of urls with htaccess

hello my url structure right now for the majority of my links is: www.url.com/category1/sample-keyword.html

I am looking to redirect them to the new url that has dropped the word sample from the url structure ie to this:

www.url.com/category1/keyword.html

what should i put in htaccess that auto redirects all the urls in the www.url.com/category1/ secti开发者_Go百科on to redirect to the new url structure?


This should do the trick:

RewriteEngine On
RewriteBase /

RewriteRule ^(.*/)sample-(.*)$     $1$2    [L,R=301]

It will match all URLS with the substring /sample- and strip it from the URL. Depending on your site organization, you may need to adjust the pattern, but that should be a good jumping-off point.


RewriteEngine On

# Redirect sample-*.html to *.html
RewriteRule ^\/?category([0-9]+)\/sample\-([^\/]+)\.html$ http://www.url.com/category$1/$2.html [R=301]

# Serve *.html
RewriteRule ^\/?category([0-9]+)\/([^\/]+)\.html$ page.php?category_id=$1&keyword=$2 [L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜