Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would like to come back to my own question and answer it. For a while now i'm using exactly what I want.</p> <p>First off I have this in my htaccess:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On # existing folders or files RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.* - [L] # non-existing folders or files RewriteRule ^(.*)/? index.php?p=$1 [L] &lt;/IfModule&gt; </code></pre> <p>This allows to access real files at all times. If the path does not exist it will pass the entire path to index.php.</p> <p>In index.php I have the following code at the top:</p> <pre><code>// Split the URL in all its components $request = parse_url(strip_tags($_GET['p'])); // Only take the path without any leading slashes $path = rtrim($request['path'], '/'); // Split each variable from eachother $path_array = explode("/", $path); if(count($path_array)){ // By default I select the first variable as the page I will include later on $page = $path_array[0]; // Each other variable I will pass as $val[#nr] starting with 1. Just to be sure I'm going to strip tags and slashes for($i=1;$i&lt;count($path_array);$i++){ $path_array[$i] = strip_tags($path_array[$i]); $path_array[$i] = stripslashes($path_array[$i]); $val[$i] = $path_array[$i]; } } else{ // If $path_array doesn't contain multiple variables lets assume $path will contain the $page $page = $path; } // If $page is empty let's take on the default page to include later on if(empty($page)){ $page = "home"; } if(file_exists($page . ".php")){ include($page . ".php"); } else{ echo "Page " . $page . ".php does not exist."; } </code></pre> <p>To give you some examples of the posibilities:</p> <p>domain.com/ will include home.php domain.com/product/ will include product.php domain.com/product/298833/ will include product.php and parse 298833 as $val[1]; domain.com/product/298833/purple-candle will include product.php and parse 298833 as $val[1]; and purple-candle as $val[2]; Notice the leading slash not being included. It does not matter.</p> <p>I'm open for improvement or tips in general. For now this is definitely the answer I was looking for back when I asked this question.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload