title: URL rewriting via Wordpress Rewrite or .htaccess
body: <p><strong>JUMP TO EDIT8 TO SEE HOW I SOLVED THIS</strong><br></p>
  
  <hr>
  
  <p>Let's say I have a Wordpress blog: <code>www.animals.com</code>. I have a certain PHP file in my theme directory: <code>www.animals.com/wp-content/themes/mytheme/db.php</code>. Also, I have a custom template for that page, so I create a new page in the Wordpress administration panel to show <code>db.php</code>: <code>www.animals.com/database</code>.</p>
  
  <p>So if I want to read something about lions, I just go to: <code>www.animals.com/database/?animal=lion</code> (because that's the way I decided to write the PHP, inserting the value from $_GET['animal'] into the query, using PDO etc.).</p>
  
  <p><strong>Now, I would like to access <code>www.animals.com/database/?animal=lion</code> as <code>www.animals.com/lion</code>.</strong></p>
  
  <p>Should I use .htaccess or Wordpress Rewrite? Where should I place my .htaccess, in the root of the Wordpress folder (with wp-config.php and those files) or in my theme directory?</p>
  
  <p>The one from the root has <code>RewriteBase /</code> and stuff from Wordpress by default. What should I write to achieve what I want? Should I put it before or after the existing code?</p>
  
  <p><strong>EDIT</strong>: this is my <strong>public_html</strong> .htaccess and this is what I <strong>really</strong> want to do:
  I have a website: <code>www.domain.com</code> and when you type this <code>http://www.domain.com/dios/?dios=agni</code> it shows you the info about the god Agni. I would like to type <code>www.domain.com/dioses/agni</code> to access the info about the god Agni. The PHP file is in <code>www.domain.com/wp-content/themes/smitespain/dios.php</code>
  It's not working x_x</p>
  
  <pre><code># BEGIN WordPress
  &lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  RewriteRule ^dioses/(\w*)$ dios/?dios=$1 [NC,L]
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  
  # END WordPress
  </code></pre>
  
  <p><strong>EDIT2</strong>: i'm using multisite <strong>(check EDIT4)</strong>, and again, /database/ /dios/ and /dioses/ are <strong>not</strong> actual folders I created, thats the name for the page I created in Wordpress. The thing is, now it shows the name of the god in the tab title :S that means the variable $_GET['dios'] is set, but it doesnt load the file (dios.php) =/</p>
  
  <p><strong>EDIT3</strong>: I need to access domain.com/dios/?dios=agni specifically, because thats the URL that will let the PHP file (dios.php) to load get_header() from wordpress, so i cant access the file directly</p>
  
  <p><strong>EDIT4</strong>: I decided to remove the multisite thing</p>
  
  <p><strong>EDIT5</strong>: these are the Wordpress pages I have:
  <code>domain.com/dioses/</code> for <code>(www.domain.com/wp-content/themes/smitespain/dioses.php)</code><br>
  <code>domain.com/dios/?dios=thor</code> for <code>(www.domain.com/wp-content/themes/smitespain/dios.php)</code></p>
  
  <p><strong>EDIT6</strong>: i was reading something in the wordpress codex..and realized that, if i wanna go to <code>domain.com/dioses</code> i can access it by going to <code>domain.com/index.php?pagename=dioses</code> or <code>domain.com/?pagename=dioses</code><br>
  So, i added this between the <code>Rewritebase /</code> and the next rule: <code>RewriteRule example/test ?pagename=dioses</code> and <code>domain.com/example/test</code> redirects me to <code>domain.com/dioses</code> but it also changes the url in the address bar :(<br>
  The thing is, if i try this: <code>RewriteRule example/test ?pagename=dios&amp;dios=thor</code> it will send me to the page 'dios' without the '?dios=thor'</p>
  
  <p><strong>EDIT7</strong>: i started using wordpress rewrite, i added this to my theme's functions.php:<br></p>
  
  <pre><code>function my_rewrite_rules() {  
      add_rewrite_rule(  
          'blah',
          'index.php?pagename=dios&amp;dios=agni',  
          'top'  
      );  
  }  
  add_action( 'init', 'my_rewrite_rules' );
  </code></pre>
  
  <p>and again..it loads the page dios, without the ?dios=agni</p>
  
  <p><strong>EDIT8</strong>: and finally, I managed to make it work =)<br>
  the first thing i needed to know is, the new <code>?dios=XXXX</code> will be no longer available to <code>$_GET['dios']</code> instead, you need to call <code>$wp_query-&gt;query_vars['dios']</code> so i added this to my theme's functions.php</p>
  
  <pre><code>function add_query_vars($new_var) {
  $new_var[] = "dios";
  return $new_var;
  }
  add_filter('query_vars', 'add_query_vars');
  
  function add_rewrite_rules($rules) {
  $new_rules = array('([^/]+)' =&gt; 'index.php?pagename=dios&amp;dios=$matches[1]');
  $rules = $new_rules + $rules;
  return $rules;
  }
  add_filter('rewrite_rules_array', 'add_rewrite_rules');
  </code></pre>
  
  <p>i make sure <code>$wp_query-&gt;query_vars['dios']</code> is actually set<br>
  then i just add the regular rule</p>