I have been attempting to use mod_rewrite to pass an invalid URL directory as a variable to PHP scripts but remain in the URL.
Example:
http://my.test.com/mydir redirects to http://my.test.com/index.php?dir=mydir but URL shows http://my.test.com/mydir
and
http://my.test.com/mydir/example.php redirects to http://my.test.com/example.php but URL displays http://my.test.com/mydir/example.php
This will be for many PHP scripts that would keep the directory in the URL. I need the css/js/imgs directories to still be accessible. I believe I can do this using the base href in my html head. I am trying to keep the invalid directory in the URL at all times.
With my current example if I call
it displays the index.php and the URL stays the same. If I call
http://my.test.com/mydir/index.php it gives me a 404 error.
I have tried every example on stack overflow as well as too many to count from Google searches. I figure after two days trying I need to get a little help.
My .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?c=$1
RewriteRule ^([^/\.]+)/([^/\.]+)?$ index.php?url=$2&c=$1 [L]
My index.php I am using for testing:
<?php
if (isset($_GET['c'])) {
$companyid = $_GET['c'];
}
if (isset($_GET['url'])) {
$url = $_GET['url'];
}
echo "DEBUG: " . $companyid . "<br>";
echo "DEBUG: " . $url;
exit;
?>