title: htaccess url rewrite confusion about request_uri
body: <p>I'm (sometimes) somehow managing to url rewriting successfully but I want to understand the core of what I'm actually doing.</p>
  
  <p>Now, whenever I type <code>http://localhost/admin/shop/</code> to the browser's address bar, I'd like my htaccess to rewrite the url as <code>http://localhost/admin.php?page=shop</code> so in the php I can understand that I'm actually dealing with shop page. For this, I have:</p>
  
  <pre><code>RewriteEngine on
  RewriteRule ^(.*)\$ $1.php [nc]
  
  RewriteCond %{REQUEST_URI} ^/admin\.php/[^/]+/$
  RewriteRule ^admin\.php/(.*)/$ admin\.php?pval=$1 [l,nc]
  </code></pre>
  
  <p>This works so far. But I'd like to understand why my code doesn't work when I do this:</p>
  
  <pre><code>###RewriteEngine on
  ###RewriteRule ^(.*)\$ $1.php [nc]
  
  ### note the commenting out the code above    
  
  RewriteCond %{REQUEST_URI} ^/admin/[^/]+/$
  RewriteRule ^admin/(.*)/$ admin?pval=$1 [l,nc]
  
  ### note the removal of '\.php' 
  </code></pre>
  
  <p>So basically, when you type 'http://localhost/admin/shop/' to the address bar, php's <code>$_SERVER['REQUEST_URI']</code> will print out exactly /admin/shop/. Now, assuming php's <code>REQUEST_URI</code> is like that, htaccess REQUEST_URI should be the same right? I don't really know if they are using different engines but that's what comes logical to me. So, assuming that I'm right, why the second example doesn't work when I remove the '.php' from the <code>RewriteCond</code> and <code>RewriteRule</code>? Also, if I'd had the chance to print the REQUEST_URI of htaccess, what would it actually print to the screen in the above example?</p>
  
  <p>PS: I know that for this case, I don't really need to use htaccess as I can create a folder inside admin folder and name it shop and so on. But the thing is that I don't really have an admin folder as I'm using controllers and a simple switch in the admin.php to avoid creating millions of folders inside my application. This is just simpler to me. </p>