Need Help Redirecting Dynamic URL to Already Exisitng URL

I have been reading many forums and tutorials on mod_rewrite, but the truth is, I am very inexperienced in this area and unfortunately have the responsibility of successfully executing these redirects.

I am trying to 301 redirect 3 dynamic URLs to the existing homepage

I’m not sure if I should use a {Query_String} rewrite or something like this:

RewriteRule ^([a-z/]+)\.html$ $1.php [R=301,L] I’m also not sure if I should write separate rules for each domain or use one rule for all three. Any insight would really be appreciated.

mod_rewrite is enabled on my .htaccess File.


If you want to be more experienced in this (mod_rewrite) area, I offer the tutorial article linked in my signature as it was developed and used by many SitePoint members over the last 5-6 years.

I do not like to provide code here because “script kiddies” do not learn and that’s my intent for being here (“share the knowledge”). However, your request is so simple, I’ll go ahead and help with the code provided you read enough of the tutorial that you understand what the code is doing.

RewriteEngine on

RewriteCond %{QUERY_STRING} ^main_page=product_info&cPath=8_251_81&products_id=603$
RewriteRule ^index\\.php$ [R=301,L]

RewriteCond %{QUERY_STRING} ^cPath=8_17_161$
RewriteRule ^wine-cabinets-perlick-stand-alone-frw$ [R=301,L]

RewriteCond %{QUERY_STRING} ^cPath=8_12_102$
RewriteRule ^dometic-wine-cabinets-dom-cs52vs$ [R=301,L]

You were quite correct in saying that you should use an Apache variable (other than {REQUEST_URI}) to access the query string and, because RewriteRules can only access {REQUEST_URI}, you must use RewriteCond’s to test the query string.

I could not combine these three RewriteRule sets because the target scripts (pages?) were different.




Your help is greatly appreciated and I looking forward to reading your tutorial; it’s important to me to gain an understanding of mod_rewrite for future instances.

Thank you,


These I’m sure are rather trivial questions, but is there a specific place on the .htaccess file to put the script? Also, do you use the script in addition to or instead of the regular 301 redirects? I have tried both, but am unable to get it to work.


I don’t believe that it matters but Apache will process core directives before mod_rewrite every time. Therefore, as a matter of process (so my thinking remains inline with the server’s processing, I put all core directives (Options, <File>, DirectoryIndex, ErrorDocument and, yes, Redirect) at the top then add my mod_rewrite after that.