开发者

.htaccess page redirect

I have dynamically created image links coming to my index.html page. basically they look like: http://catdeoderant.com/index.html?catpart=view&catimage=13

How do I use .htaccess to redirect these links to: http://catdeoderant.com/stinkycats/gallery.php

I need it where when you click on an image the redirect happens. I also need the variables to be passed to the redirected page. The first variable will always be =view, but the second could be any number.

One more thing, since it's an index.html page, any link to index.html with no variables should not get redirected开发者_JAVA百科.

Thanks all, and I do love cats, but sometimes they do stink!


Use the following rule:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{QUERY_STRING}  ^catpart=view&catimage=([0-9]+)$
  RewriteRule ^/index.html$  /stinkycats/gallery.php [R=301,L]
</IfModule>

Edited on advice from LazyOne.

Expected result:

  • index.html => index.html
  • index.html?foo=bar => index.html
  • index.html?catpart=view => index.html
  • index.html?catpart=view&catimage=foobar => index.html
  • index.html?catpart=view&catimage=13 => /stinkycats/gallery.php?catpart=view&catimage=13

I never used %{QUERY_STRING} before but it should be close to what you are trying to do according to this documentation http://fantomaster.com/faarticles/rewritingurls.txt

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜