views:

45

answers:

1

Problem: Visitors open the url website.com/?i=133r534|213213|12312312 but this url isn't valid anymore and they need to be forwarded to website.com/#Videos:133r534|213213|12312312

What I've tried: During the last hours I tried many mod_rewrite (.htaccess) rules with using Query_String, all failed. The last message in this topic shows a solution for this problem, but what would be the rule in my situation.

I'm very curious how you would solve this problem :)!

+1  A: 

The following will handle the simple case you show. You'll need to add additional logic if you need to allow for other parameters in the query string or file names before the ?.

RewriteEngine On
RewriteCond %{QUERY_STRING} ^i=(.*)
RewriteRule ^.*  /#Video:%1? [NE,R=permanent]

Why is this tricky?

  • RewriteRule doesn't look at the query string, so you have to use RewriteCond to evaluate the QUERY_STRING variable and capture the part you'll need later (referenced via %1)
  • the hash character (#) is normally escaped, you must specify the [NE] flag
  • The trailing ? on the substitution string is required to suppress the original query string

I tested this on Apache 2.2.

TomG
Great Tom! Thanks a lot, this one works for me and I get the concept now :)
MeProtozoan