I have a website that relies on GET parameters to show users the correct information. However, it looks kind of ugly this way, so I wanted to change it so it looks like a normal file structure.
I was hoping to accomplish this with PHP. I am sure there are plenty on online guides on the subject (And it has certainly been done before) but I do not know what this is called, so my searches yield no results.
The only other thing is that PHP still needs to read it as a GET parameter in order to collect the correct information from the database and display it.
It is typically done by the server, Eg: on Apache in the .htaccess file. Though there are ways in PHP.
Looking at your examples, if you are going to do this, go all the way and have something like:-
You can create mod rewrite rules in a .htaccess file for a server using apache. However, the more modern approach is to ROUTE the request in the application itself not using archaic server rewrites. This is one of many great things most frameworks will handle for you.
Yes, if you are using a framework, it may well handle it all for you.
But if you are not, and don’t want to use .htaccess (you may not even be on Apache) you can pull parts of the URL into your router script from values in the $_SERVER global and deal with it there
That looks pretty complicated. With over 250 pages on the domain, with plans to add an additional 200, I think that would only slow things down, and use more resources.
I actually think having a single entry point will simplify your work with many pages. Once you get your head around the idea.
If you are already doing things like:-
viewAccount.php?account_id=id_10464141
You are familiar with the idea that the one script on page viewAccount.php can display any number of different web pages.
It is really just an extension of that concept. So if all you had in the public root was index.php, the script in that file (or possibly one required by it) could show absolutely any number of pages, depending on what was in the requested URL.
Application level routing is much more flexible. For example, users can define component paths saved to a database. When users access the path the mapping can dynamically be discovered by querying the database. Mappings can be dynamically loaded in such a way in .htaccess without resorting to passing the path into the app layer and having it discover the component to render.
For example, in the platform I’m creating users can create path mappings for two separate assets.
pages
external applications
The database pictured below can be queried for a match and app can then render the associated component in the json for the mapping. The discovery strategy is currently based on matching the site and path of the object. The site filter isn’t included below because currently there is only one site.
I also have future plans to extend this discovery mechanism to not only include site, path but other attributes as well like auth info, device, screen size. Where a user accessing a device on one device might see a different page than a user accessing on another device type like a phone. Another example could be dedicated displays for specific users based on auth info rule matching.
This is the mechanism by which this demo page is pre-rendered to static html.
This doesn’t use a server. Instead the query to discover the route is done directly in the browser. That can be seen by looking at the request pictured below. The domain is *.amazonaws.com is aws not a proxy or middle layer but straight up aws managed open search instance.
This doesn’t use a server. Instead the query to discover the route is done directly in the browser. That can be seen by looking at the request pictured below. The domain is *.amazonaws.com is aws not a proxy or middle layer but straight up aws managed open search instance.
This is JavaScript or more specifically Angular. None the less, the same fundamental dynamic routing can be achieved with all languages and many frameworks. The only difference is that instead of doing it in the browser the routing would be handled on the server in the app layer.
.htaccess can show error messages? How would I turn those on?
I think my hosting provider may be restricting the function, but I will check it again later since I may have mis-uploaded it due to getting angry about it.
I think it is something with my web host. I created the code below, and it does not work (See the table for response types). .htaccess code is the same as here. The URL does not change at all.