301 Htaccess RewriteRule Query_String

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 :)!


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.

Need Your Help

Body Overflowing on background

html css image background overflow

For my homepage I have a background set as width: 80%; and then aligned to center.

How to configure Maven to compile current AWS SWF code

java maven amazon-web-services aspectj-maven-plugin

For a good recent version of AWS SDK such as 1.11.28, what do I put in my pom.xml so that Maven can weave and compile everything? This topic is discussed in several places, but all answers I can f...