title: How do I create this dynamic htaccess rewrite rule?
body: <p>This permalink/friendly url:</p>
  
  <pre><code>http://anything.com/ok
  </code></pre>
  
  <p>Should be serving this path/url:</p>
  
  <pre><code>http://anything.com/path/to/page/dir1/dir2/page.php?parameter=ok
  </code></pre>
  
  <p>This works, but this is hardcoded. need dynamic method. dir1 can be anything, dir2 can be anything, and the text after parameter= can be anything.</p>
  
  <pre><code>RewriteRule ^ok/{0,1}$  path/to/page/dir1/dir2/page.php?parameter=ok [QSA,L]
  </code></pre>
  
  <p>Here are bunch of things i tried without success.</p>
  
  <pre><code>#RewriteRule ^page/([a-zA-Z0-9_-]+)$ page.php?parameter=$1
  #RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /page\.php\?parameter=([^\&amp;\ ]+)
  #RewriteRule ^/?page\.php$ /page/%1? [L,R=301]
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteRule ^path/to/page/([^/]+)/([^/]+)$ page.php?parameter=$1 [L]
  #RewriteRule ^page/{0,1}$ http://%4/path/to/page/%3/%2/page.php?parameter=%1 [QSA,L]
  #RewriteRule ^$4/{0,1} http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
  #RewriteRule ^page/{0,1}$ http://%1/path/to/page/%2/%3/page.php?parameter=%4 [QSA,L]
  #RewriteRule ^page/{0,1}$ http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
  #RewriteRule ^$ http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
  #RewriteRule ^$4 http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
  #RewriteRule ^$4 http://%1/path/to/page/%2/%3/page.php?parameter=%4 [QSA,L]
  #RewriteRule ^/{0,1}$ http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
  #RewriteRule ^/{0,1}$ http://%1/path/to/page/%2/%3/page.php?parameter=%4 [QSA,L]
  #RewriteRule ^/{0,1}$4 http://%1/path/to/page/%2/%3/page.php?parameter=%4 [QSA,L]
  #RewriteRule ^/$4 http://%1/path/to/page/%2/%3/page.php?parameter=%4 [QSA,L]
  #RewriteRule ^/$4 http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>This worked for a random parameter. Now I just need to know how to do random two folders in the middle of url.</p>
  
  <pre><code>RewriteRule ^([^/.]+)/?$ path/to/page/dir1/dir2/page.php?parameter=$1 [L]
  </code></pre>
  
  <p>Examples of random 2 folders:</p>
  
  <pre><code>/admin/11-blah/
  /development/546-whatever/
  /abc-company/46208-name-of-project/
  </code></pre>
  
  <p>Could be anything as those 2 directory names. No special characters except dash though. alphanumeric and dash.</p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>Am i to understand that the friendly rewrite has to contain all the dynamic elements of the full dirty url?</p>
  
  <p>I got this to work:</p>
  
  <pre><code>RewriteRule ^([^/.]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ path/to/page/$1/$2/page.php?parameter=$3 [L]
  </code></pre>
  
  <p>which means the clean url will look like this:</p>
  
  <pre><code>http://anything.com/admin/11-blah/ok
  </code></pre>
  
  <p>but there's no way to make it look like this?:</p>
  
  <pre><code>http://anything.com/ok
  </code></pre>