开发者

Htaccess URL redirect by matching url string and parameters

I need to match the URL format and depends on URL matches need to redirect the incoming requests to different pages.

For example

http://www.domain.com/path1/path2/ wrong-url -1/ ?var1=val1

http://www.domain.com/path1/path2/ another-wrong-url -1/ ?var1=val1

开发者_Go百科 http://www.domain.com/path1/path2/ third-wrong-url -1/?var1=val1

http://www.domain.com/path1/path2/ fourth-wrong-url -1/?var1=val1

See the High lighted URL Matches. It always having -1 as the url string. . That needs to be redirected one static page.

And some other URL's always have var1 as URL Query String parameter. So if URL have var1 as Query string then those URL's needs to be redirected to another Static page.

So i tried this but didn't worked. Please help me in this redirecting script

  RewriteEngine on
  RewriteRule ^(path1/path2/[^-1]*)$ http://www.domain.com/target-page [L,R=301]


1. Rule for URL that ends with -1/:

RewriteRule ^path1/path2/([^/]+)-1/$ http://www.domain.com/target-page [L,R=301]

2. Rule for having var1= parameter in query string:

RewriteCond %{QUERY_STRING} (^|&)var1=([^&]*)(&|$)
RewriteRule .* http://www.domain.com/another-target-page [L,R=301]

NOTE: With these rules existing query string will be passed to a new URL as well (e.g. /path1/path2/wrong-url-1/?say=meow will become http://www.domain.com/target-page?say=meow). To drop it, add ? at the end of target URL (e.g. http://www.domain.com/another-target-page? [L,R=301]

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜