I would like to know how I can use this kind of “file browsing”.
Right now all my little PHP-Web projects work by accessing directly the PHP file:
My Programs: http://website.de/profil.php or http://website.de/news.php
But I noticed that WordPress and other Websites just have folders (without an index file).
As example:
https://wordpress.org/themes/ <- works
https://wordpress.org/themes/index.php <- searches for “index.php”
or
http://localhost/wordpress/2016/05/11/hello-world/
opens a event, without a ‘2016’ folder
But on the other side:
https://wordpress.org/support/index.php =
https://wordpress.org/support/
What is the technology behind that? PHP? How could I use this in my Websites; it seams like a big deal to me.
I’m sure that there is somewhere a good guide for that, but I wouldn’t even know what to google for.
Although you can mimic “pretty” URLs on a small scale by putting an eg. index.php in a folder, the real gem comes when you make use of web server rewrites to effectively “translate” a nice URL into something the server can read.
On an Apache server, mod_rewrite is the module behind this. mod_rewrite rules go in a .htaccess file, and allow you to create quite powerful custom URL structures.
If you have a look in your .htaccess file in your test WordPress install, you’ll see the rewrite rules that point every request on the site to index.php.
Internally, Apache then translates a post URL that looks like it is in several folders into something like http://localhost/wordpress/index.php?year=2016&month=05&date=11&post_name=hello-world. The visitor will only ever see the “pretty” URL: http://localhost/wordpress/2016/05/11/hello-world/
From here, WordPress then internally deals with the URL to display the correct post, date archive, category archive etc. based on what it can access in those query string variables (in PHP, these are all available in the $_GET superglobal, eg.
$_GET["year"]
.It’s worth noting too that WordPress doesn’t put all its rewrite logic straight into .htaccess, for simplicity sake it manages most of it internally, which is why it configures .htaccess to just “send everything through.”
Further topics to read about include mod_rewrite and .htaccess 🙂