I (sometimes) somehow know how to correctly rewrite the URL, but I want to understand the essence of what I'm actually doing.
Now when I type http://localhost/admin/shop/ into the address bar of the browser, I would like htaccess to rewrite the URL as http://localhost/admin.php?page=shop , so in php I can understand that Iβm actually dealing with a store page. For this I have:
RewriteEngine on RewriteRule ^(.*)\$ $1.php [nc] RewriteCond %{REQUEST_URI} ^/admin\.php/[^/]+/$ RewriteRule ^admin\.php/(.*)/$ admin\.php?pval=$1 [l,nc]
It still works. But I would like to understand why my code does not work when I do this:
RewriteRule ^(.*)\$ $1.php [nc] note the removal of '\.php'
So, when you type "http: // localhost / admin / shop /" in the address bar, php $_SERVER['REQUEST_URI'] will print exactly / admin / shop /. Now, assuming php REQUEST_URI like this, htaccess REQUEST_URI should be the same right? I really don't know if they use different engines, but that is logical for me. So, assuming I'm right, why does the second example not work when I remove the '.php' from the RewriteCond and RewriteRule ? Also, if I had the opportunity to print REQUEST_URI htaccess, what would it actually print on the screen in the above example?
PS: I know that for this case I really do not need to use htaccess, since I can create a folder inside the admin folder and call it a store and so on. But the fact is, I donβt actually have an admin folder, since I use controllers and a simple switch in admin.php to avoid creating millions of folders inside my application. For me it's just easier.
source share