This question already has an answer here:
- Seo Friendly Url css img js not working 2 answers
I'm running a localhost on my Mac using the native sites, and I can't seem to get .htaccess CSS working. I'm using an index.php page, that is then given url variables to tell which page to display (ex. index.php?login
). There two issues I'm facing here: The first is that it redirects to a page where my global styles aren't included, and the second is that it shows the homepage instead of my login page.
I've tried navigating to the rewritten site as localhost/index.php?login
, and all the CSS and HTML displays fine. It's only when I rewrite it as localhost/login
that it fails. It shows my homepage without any of the styles that should be include from index.php
Here is my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
DirectoryIndex index.php
RewriteRule ^login$ index.php?login [NC]
</IfModule>
Here is my index.php
//Check for more GET variables.
$url = $_SERVER['REQUEST_URI'];
$split = explode("?", $url);
if (isset($split[1])) {
$newvarsarray = explode("&", $split[1]);
foreach ($newvarsarray as $newvar) {
$keyandvalue = explode("=", $newvar);
if (isset($keyandvalue[1])) {
$_GET[$keyandvalue[0]] = $keyandvalue[1];
} else {
$_GET[$keyandvalue[0]] = '';
}
}
} else {
//No additional vars, leave $_GET alone.
}
include_once 'globalheader.html';//Imports styles and things
include_once 'header.html';//Stylized header
//This is the area where we handle the different states of the webpage and import them into here
if (empty($_GET)) {
//Main homepage
include_once 'mainpage.html';
} else if (isset($_GET['login'])) {
//Login page
include_once 'login.html';
} else if (isset($_GET['register'])) {
//Register page
include_once 'register.html';
} else if (isset($_GET['profile'])) {
//Profile page
}
include_once 'footer.html';//Stylized footer
include_once 'globalfooter.html';//Closes things from globalheader.html
?>
I want it to display the correct page with correct CSS instead of seemingly skipping over the entirety of index.php and just using the .html file.
</div>