Note that there are some explanatory texts on larger screens.

plurals
  1. POApache or PHP redirecting to odd URL
    primarykey
    data
    text
    <p>I am trying to set up a dynamic application-serving framework for a development test.</p> <p>My desired outcome is that when a user goes to a URL, if it is formatted like <code>hostname.com/somecategory/someapplicationname/</code> or <code>hostname.com/somecategory/someapplicationname</code> (without the slash at the end), it should serve the user the requested application from the database, as long as the category and application name exists as a key.</p> <p>I have a special case where some applications are not in the database, and they exist on file with that same URL, so we serve the existing file with priority over any database records.</p> <p>The case with dynamic content from the database works fine. The case for the existing file works 100% only if there is a slash at the end. If the slash is not there, it will serve the right file, BUT the URL looks rather odd. It'll show: <code>hostname.com/somecategory/someapplicationname/?category=somecategory&amp;appname=someapplicationname</code><br> So, it works, but the unexpected output makes me feel that the solution is not complete.</p> <p>I am using apache mod_rewrite, and my .htaccess file is as follows:</p> <pre><code>RewriteEngine on RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ route.php?category=$1&amp;appname=$2 [NC,L] </code></pre> <p>The PHP code specific to this case is as follows. I stripped the validation and database connection from this snippet for simplicity of reading, but the logic for this particular case is preserved.</p> <pre><code>$file = $_SERVER['DOCUMENT_ROOT'] . $_GET['category'] . "/" . $_GET['appname'] . "/index.php"; $fileNoPHP = $_SERVER['DOCUMENT_ROOT'] . $_GET['category'] . "/" . $_GET['appname'] . "/index.html"; $_fileExists = file_exists($file); $_fileNoPHPExists = file_exists($fileNoPHP); include_once($_fileExists ? $file : $fileNoPHP); </code></pre> <p>To be clear, my question is: Why is my existing file case appending the GET parameters to the end of the URL, ONLY when the slash at the end is not there?</p> <p>Thanks for your time. If you need further information, please let me know and I will provide.</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