title: .htaccess to Redirect Instances of a Specific Nested Page
body: <p>I have a url that contains generated strings that I need to redirect so that it sits just under the domain name. (example.. site.com/pagename.html)</p>
  
  <p>I only want instances to redirect if it is nested under a page (or alternatively, if there is a way to exclude site.com/pagename.html from redirecting to itself)</p>
  
  <p>So for example.. site.com/page1/pagename.html?string=stuff should 301 redirect to site.com/pagename.html and carry over the string.</p>
  
  <p>However I do not want the rule to redirect any just instance if "pagename.html" as I need to prevent it from looping. Also I can not reference /page1/ in this example as there are thousands of instances of different parent pages so I believe I need to use a wildcard or regular expression to make this work.</p>
  
  <p>Any help would be MUCH appreciated as I barely know html. </p>
  
  <p>So far I have tested this and it carries over the string that follows the page name succcesfully. But now I need to replace "test" with "pagename" and either make an exclusion or create a condition..</p>
  
  <pre><code># Rewriting
  RewriteEngine On
  
  # 301 Redirect 1
  RewriteRule ^test\.html$ /pagename.html [R=301,NE,NC,L]
  </code></pre>