jrws Posted April 19, 2009 Share Posted April 19, 2009 Hey guys, I have recently stumbled across this, I understand how to use mod_rewrite and I am happy, however: When I use the new shorter url I have no styling or javascript. Although the link to the style sheet and javascript show, neither work. What do I do? Here is the header file: <?php require_once ('libary/config.php'); require_once ('libary/functions.php'); //Header session_start(); ob_start(); error_reporting(1); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head><title><?= $title . '---' . $siteName; ?></title> <link rel="stylesheet" type="text/css" href="./libary/default.css"> <script type = "text/javascript" src="./libary/main.js"></script> </head> <body> <? if (isset($_COOKIE['username']) && isset($_COOKIE['u_level']) && isset($_COOKIE['u_id']) && isset($_COOKIE['password'])) { //$id = $_COOKIE['u_id']; $sql = "SELECT username AND password FROM user WHERE username = '{$_COOKIE['username']}'AND password ='{$_COOKIE['password']}'"; $result = mysql_query($sql) or die(mysql_error()); //$row = mysql_fetch_array($result); if (mysql_num_rows($result) == 1) //If the username and password combination exist set the sessions { $_SESSION['username'] = $_COOKIE['username']; $_SESSION['u_level'] = $_COOKIE['u_level']; $_SESSION['u_id'] = $_COOKIE['u_id']; $_SESSION['password'] = 1; //echo 'Success'; } else { header('Location: '.$siteURL.'logout.php'); exit(); } } if (isset($_SESSION['username']) && $_SESSION['password'] == 1 && $_SESSION['u_level'] == 6) { ?><div class="holder"> <div id="header"> |<a href="<?= $siteURL; ?>">Home</a>| <a href="<? $siteURL; ?>new_news.php">Post news</a>| <a href="<? $siteURL; ?>view_news.php">View all the news</a>| <a href="<? $siteURL; ?>admin.php">Admin page</a>| <a href="<? $siteURL; ?>profile.php?id=<?= $_SESSION['u_id']; ?>">Your profile</a>| <a href="<? $siteURL; ?>profile.php">All profiles</a>| <a href="<?= $siteURL; ?>logout.php" onClick="return verify('Are you sure you want to logout?')" >Logout</a>| </div> <? } elseif (isset($_SESSION['username']) && $_SESSION['password'] == 1) { ?> <div class="holder"> <div id="header"> |<a href="<?= $siteURL; ?>">Home</a>| <a href="<?= $siteURL; ?>new_news.php">Post news</a>| <a href="<?= $siteURL; ?>view_news.php">View all the news</a>| <a href="<?= $siteURL; ?>profile.php?id=<?= $_SESSION['u_id']; ?>">Your profile</a>| <a href="<?= $siteURL; ?>profile.php">All profiles</a>| <a href="<?= $siteURL; ?>logout.php" onClick="return verify('Are you sure you want to logout?')">Logout</a>| </div><? } else { ?> <div class="holder"> <div id="header"> |<a href="<?= $siteURL; ?>">Home</a>| <a href="<?= $siteURL; ?>login.php">Login</a>| <a href="<?= $siteURL; ?>register.php">Register</a>| <a href="<?= $siteURL; ?>view_news.php">View all the news</a>| </div> <? } ?> Here is the .htaccess: #.htaccess RewriteEngine On # Turn on the rewriting engine RewriteRule ^news/?$ view_news.php [NC,L] # Handle news requests RewriteRule ^news/([0-9]+)/?$ view_news.php?=$1 [NC,L] # Handle news requests Note that the first one includes the style sheet and css, the second one doesn't. BTW here is the output from the second one: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head><title>News---Doonside Technology High</title> <link rel="stylesheet" type="text/css" href="./libary/default.css"> <script type = "text/javascript" src="./libary/main.js"></script> </head> <body> <div class="holder"> <div id="header"> |<a href="http://localhost/school%20site/">Home</a>| <a href="http://localhost/school%20site/login.php">Login</a>| <a href="http://localhost/school%20site/register.php">Register</a>| <a href="http://localhost/school%20site/view_news.php">View all the news</a>| </div> <b>Test</b><br />Test<br /><a href="?id=1">View this post</a><br/><br><b>TEst</b><br />Test<br /><a href="?id=2">View this post</a><br/><br> [<b>1</b>] <div id="footer"> 19 April 2009 6:07:48 PM<br><small>Powered By Kardaina Entertainment©</small></div> </div> </body> </html> Please help, and thanks for your time; -James- Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/ Share on other sites More sharing options...
jrws Posted April 20, 2009 Author Share Posted April 20, 2009 I have noticed, that if I change the url to http://localhost/school%20site/news/ The css and javascript exist. I also noticed that when I click on links from that page the link is something like this: http://localhost/school%20site//news/news Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-814241 Share on other sites More sharing options...
jackpf Posted April 20, 2009 Share Posted April 20, 2009 You have relative links to your js/css. You need to do it like http://www.yoursite.com/css.css,or precede with a backslash. Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-814254 Share on other sites More sharing options...
jrws Posted April 20, 2009 Author Share Posted April 20, 2009 Sorry, I am sure that the message is helpful, however I do not understand. But thank you for helping -James- Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-814290 Share on other sites More sharing options...
jackpf Posted April 20, 2009 Share Posted April 20, 2009 If you're using rewrites, if your links are relative, the client pc is going to be looking in them relative to the current directory. And since this directory is virtual, the actual css/js file probably does not exist. For example, if your current virtual directory is http://www.yourdomain.com/something/something-else, it's going to look for your css file in http://www.yourdomain.com/something/something-else/css.css which obviously does not exist. If you give your css file an absolute reference, liike http://www.yourdomain.com/css.css, it will always look for it in that place. Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-814361 Share on other sites More sharing options...
jrws Posted April 20, 2009 Author Share Posted April 20, 2009 Thanks for clearing that up, I have tried that, however now the rewrite wont work, I get a 404, the only thing I changed was the absolute as you suggested, I have not edited the .htaccess file. So I am stuck, and I have no idea as to why this would happen. But thank you, hopefully the bloody thing will work again. -James- Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-815095 Share on other sites More sharing options...
jackpf Posted April 21, 2009 Share Posted April 21, 2009 Changing the links should not give you a 404; something else must have been changed. If the css/js file is not present, it just won't include it, it shouldn't give you a 404. Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-815372 Share on other sites More sharing options...
jrws Posted April 22, 2009 Author Share Posted April 22, 2009 Yeah I know, so now I don't know whats wrong... Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-816012 Share on other sites More sharing options...
jackpf Posted April 22, 2009 Share Posted April 22, 2009 Could you provide a link to your site? I could have a quick look, see if there's anything obviously wrong with it. Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-816255 Share on other sites More sharing options...
jrws Posted April 23, 2009 Author Share Posted April 23, 2009 It is on local host, however I will upload onto a free website if you like. Once it's uploaded it will be on www.sandstorm.net46.net EDIT: When I tested it on the website everything seemed to be working ok, so why isn't it working on localhost.... Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-817110 Share on other sites More sharing options...
jackpf Posted April 23, 2009 Share Posted April 23, 2009 Have you got mod rewrite turned on on your apache? Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-817221 Share on other sites More sharing options...
jrws Posted April 24, 2009 Author Share Posted April 24, 2009 On the localhost, yes. Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-817974 Share on other sites More sharing options...
jrws Posted April 27, 2009 Author Share Posted April 27, 2009 Its been awhile, can anyone help me so I can still test on localhost? Or is this no longer possible? Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-820123 Share on other sites More sharing options...
jackpf Posted April 27, 2009 Share Posted April 27, 2009 I'd say it was something to do with your apache configuration, probably something to do with mod rewrite. Probably just needs a play with. Quote Link to comment https://forums.phpfreaks.com/topic/154725-css-and-javascript-disappeared/#findComment-820135 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.