Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › mod_rewrite acting weird
New Posts  All Forums:Forum Nav:

mod_rewrite acting weird

post #1 of 4
Thread Starter 
I am trying to make my website more idiot proof and I have run into an odd problem with it. I am using simple php to navigate within my website and then using mod_rewrite to clean it up. The problem is for some reason there are urls that you can type that will bring up the page but the css doesn't load.

What I do with mod_rewite is take everything that is a-z A-Z 0-9 and a / and write it to a variable called 'page'. I then take the variable and explode it by / into an array. I can then use the first argument of the array to decide what content to display.

Here are some examples

works
does not work
These all resolve to the same thing but the last two don't bring up the css.

Here is the code I am using

index.php Probably not relevant
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<title>Revo-D</title>
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
</head>
<body>
<table width="100%"><tr><td align="center">
<table width="920px"><tr><td>
<?php 
include("content/menu.php");
?>
</td></tr></table>
</td></tr></table>
</body>
</html>
menu.php
Code:
<div id="menu"><ul>
<li><a href='/'>Home</a></li>
<li><a href='/mods'>Mods</a></li>
<li><a href='/maps'>Maps</a></li>
<li><a href='/contraptions'>Contraptions</a></li>
<li><a href='/minecraft'>Minecraft</a></li>
</ul></div>
<h1 style = "padding:0 20px;">Revo-D</h1>
<div style="height: 45px; overflow: hidden; width: 920px;"></div>

<?php
if (isset($_GET['page']))
{
$page = $_GET['page'];
$page = explode("/", $page);
$page = strtolower($page[0]);
if ($page == mods)
{
include("content/mods.php");
}
elseif ($page == maps)
{
include("content/maps.php");
}
elseif ($page == contraptions)
{
include("content/contraptions.php");
}
elseif ($page == minecraft)
{
include("content/Minecraft.php");
}
else
{
include("content/home.php");
}
}
else
{
include("content/home.php");
}
?>

.htaccess
Code:
DirectoryIndex index.php

RewriteEngine On

RewriteRule ^([a-zA-Z0-9/]+)$ ?page=$1 [L]
Awesome you lasted this long rep to all who provide helpful insight!!
Fire Computer
(17 items)
 
Fire Yoga
(13 items)
 
Fire Server
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Ivy Bridge 3.4GHz (3.8GHz T... GIGABYTE GA-Z77X-UD5H LGA 1155 Intel Z77 HDMI S... GTX680-DC2O-2GD5 CORSAIR DOMINATOR GT 4GB 240-Pin DDR3 SDRAM DDR... 
Hard DriveHard DriveOptical DriveCooling
Seagate Samsung Light Scribe DVD Burner H50 
OSMonitorKeyboardPower
Windows 7 Professional 64 bit ASUS VH226H 21.5" Logitech G15 Corsair 850W 
CaseMouseAudioAudio
Corsair 500R Logitech M500  HDA X-Plosion 7.1 Boston Acustics BA7500 
CPUGraphicsRAMHard Drive
Intel Core i5-3317U Intel(R) HD Graphics 4000 4GB x2 128 GB SSD 
Hard DriveOS
256GB SSD Windows 8 
  hide details  
Reply
Fire Computer
(17 items)
 
Fire Yoga
(13 items)
 
Fire Server
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Ivy Bridge 3.4GHz (3.8GHz T... GIGABYTE GA-Z77X-UD5H LGA 1155 Intel Z77 HDMI S... GTX680-DC2O-2GD5 CORSAIR DOMINATOR GT 4GB 240-Pin DDR3 SDRAM DDR... 
Hard DriveHard DriveOptical DriveCooling
Seagate Samsung Light Scribe DVD Burner H50 
OSMonitorKeyboardPower
Windows 7 Professional 64 bit ASUS VH226H 21.5" Logitech G15 Corsair 850W 
CaseMouseAudioAudio
Corsair 500R Logitech M500  HDA X-Plosion 7.1 Boston Acustics BA7500 
CPUGraphicsRAMHard Drive
Intel Core i5-3317U Intel(R) HD Graphics 4000 4GB x2 128 GB SSD 
Hard DriveOS
256GB SSD Windows 8 
  hide details  
Reply
post #2 of 4
That isn't a problem with your rewrite rule, it's a problem with your HTML.

Specifically:

Code:

        <link rel="stylesheet" type="text/css" href="css/stylesheet.css"> 

You need to provide an absolute path to your stylesheet.
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
post #3 of 4
Thread Starter 
Quote:
Originally Posted by error10 View Post
That isn't a problem with your rewrite rule, it's a problem with your HTML.

Specifically:

Code:

        <link rel="stylesheet" type="text/css" href="css/stylesheet.css"> 

You need to provide an absolute path to your stylesheet.

Awesome that did the trick! I wonder though if there is a way to make it a relative path to improve portability but that's not that important. Erm... an imaginary rep for you I guess is all I can do.
Fire Computer
(17 items)
 
Fire Yoga
(13 items)
 
Fire Server
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Ivy Bridge 3.4GHz (3.8GHz T... GIGABYTE GA-Z77X-UD5H LGA 1155 Intel Z77 HDMI S... GTX680-DC2O-2GD5 CORSAIR DOMINATOR GT 4GB 240-Pin DDR3 SDRAM DDR... 
Hard DriveHard DriveOptical DriveCooling
Seagate Samsung Light Scribe DVD Burner H50 
OSMonitorKeyboardPower
Windows 7 Professional 64 bit ASUS VH226H 21.5" Logitech G15 Corsair 850W 
CaseMouseAudioAudio
Corsair 500R Logitech M500  HDA X-Plosion 7.1 Boston Acustics BA7500 
CPUGraphicsRAMHard Drive
Intel Core i5-3317U Intel(R) HD Graphics 4000 4GB x2 128 GB SSD 
Hard DriveOS
256GB SSD Windows 8 
  hide details  
Reply
Fire Computer
(17 items)
 
Fire Yoga
(13 items)
 
Fire Server
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Ivy Bridge 3.4GHz (3.8GHz T... GIGABYTE GA-Z77X-UD5H LGA 1155 Intel Z77 HDMI S... GTX680-DC2O-2GD5 CORSAIR DOMINATOR GT 4GB 240-Pin DDR3 SDRAM DDR... 
Hard DriveHard DriveOptical DriveCooling
Seagate Samsung Light Scribe DVD Burner H50 
OSMonitorKeyboardPower
Windows 7 Professional 64 bit ASUS VH226H 21.5" Logitech G15 Corsair 850W 
CaseMouseAudioAudio
Corsair 500R Logitech M500  HDA X-Plosion 7.1 Boston Acustics BA7500 
CPUGraphicsRAMHard Drive
Intel Core i5-3317U Intel(R) HD Graphics 4000 4GB x2 128 GB SSD 
Hard DriveOS
256GB SSD Windows 8 
  hide details  
Reply
post #4 of 4
Quote:
Originally Posted by FireMarshallBill View Post
Awesome that did the trick! I wonder though if there is a way to make it a relative path to improve portability but that's not that important. Erm... an imaginary rep for you I guess is all I can do.
Not if you intend to rewrite URLs with path separators in them. Sorry.
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › mod_rewrite acting weird