.htaccess Rewrite the question
The ways of handling it via .htaccess Rewrite can cause a little headache. This is similar to the basic answer, but if you don't use regex you are at a loss.
There are several ways to handle this. I assume you only have index.php, submit.php and view.php with an associated id.
RewriteEngine On RewriteRule ^ (index | submit | view) / (\ d +) $ /$1.php?id=$2 RewriteRule ^ (index | submit | view) / (\ d +) $ /$1.php
This is how it works: you tell .htaccess to enable the Rewrite Engine. Step 2, you give the site a parameter that tells it how it's done. The parameter in this case reads: At the beginning of the URL, after the domain name, check for an index, submit, or browse. If they exist, it will look for an identifier. If both exist, it will return the value in PHP as /(index, submit, or view)?id=$id
.
The second option is in case the identifier is not viable.
This is an easy way to deal with it. A more complicated way of handling it would be ...
RewriteEngine On RewriteRule ^ ([az] +) /? (\ D +)? $ /$1.php?id=$2
This will load whatever is written in normal alphabetic characters only in upper and lower case letters, use that as the filename, and then find that the id is even needed - it will load without.
You must make sure to include some safeguards in your strings $_GET
to return errors if the names are wrong or return nothing of value.
You should play with it, investigate regex over a cup of coffee and something alcoholic (I believe regex is the cause of type 1 alcoholism in modern programmers, but I could be wrong; -P ...) til you will find the schema that fits comfortably on your system.
As a side note, you can have as many RewriteRules as you like, but they are always processed from the top. I realize this sounds like common sense, but it's important to know when to debug.
a source to share