Forum Moderators: phranque

Message Too Old, No Replies

The compiler does not execute my external style sheet.

The compiler does not execute my external style sheet.

         

xbl01234

11:05 am on Sep 17, 2007 (gmt 0)

10+ Year Member



Hi;
I wrote a rewrite rule for creatting dynamic url as following:
RewriteEngine On
RewriteRule ^country/([0-9]+)/$ Category.php?page=$1 [L]


But the problem i have is that the compiler does not execute the external style sheet
from the Category.php, it just execute the internal style sheet in Category.php, when
i try to cretae a dynamic URL from the file of the Category.php.

Could any tell me why? and i have to use the internal style sheet?

i have tow files as following:

Index.php


<html>
<body>
<a href="Category.php"> go to Category file </a>
</body>
</html>

Category.php


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title> Welcome to my page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

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

</head>

<body>
<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="#" id="current">Home</a></li>
<li><a href="#">Contact Us </a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Help</a></li>
</ul>
</div>

<a href="/country/2/"> This is the link for the Url redirection testting </a>

</body>
</html>

when i click the link from the file of the Category.php, the compiler does not
execute the external style sheet, but it works for the internal style sheet.

if i use the following replace the external style sheet, the compiler will execute that:


<style type="text/css">
body
{
margin: 0;
padding: 0;
}
#navcontainer ul
{
text-align: center;
padding: 4px;
background-color: #0e10f6;
margin-left: 0;
margin-top: 5px;
width: 100%;
font-family: Arial, Helvetica, sans-serif;
line-height: 18px;
}

#navcontainer ul li
{

display: inline;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 0;
padding-right: 0;
}

#navcontainer ul li a
{

border-right: 1px solid #fff;
padding-left: 10px;
padding-right: 10px;
padding-top: 5px;
padding-bottom: 5px;
color: white;
text-decoration: none;


}

#navcontainer ul li a:hover
{
background-color: #09236c;
color: white;
}

#navcontainer #active
{
border-left: 1px solid #fff;
}

</style>

jdMorgan

1:08 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's no compiler involved here. It is the client (browser in this case) that fetches and interprets the stylesheet.

From a post yesterday:

[quot] ...it could "not work" because page-relative links on the pages being produced can't be properly resolved by the client, causing broken images, external CSS, and external JS links. Or it could be anything in between...

More on that: It is the client (browser or 'bot) that resolves page-relative links on pages. It does so using the current 'page' URL shown in the address bar. So, if you're rewriting those 'pages' on the server, the browser doesn't know that, and will request page-linked objects using the page address it knows about -- the one in the address bar. The two solutions are to either rewrite the object requests in addition to the page requests themselves, or to use server-relative or canonical URLs in the on-page object references. i.e. use <img src="/images/logo.gif> or <img src="http://example.com/images/logo.gif"> rather than <img src="images/logo.gif"> [/quote]
Jim

xbl01234

10:41 am on Sep 18, 2007 (gmt 0)

10+ Year Member



Thanks, i choice the server-relative URL for my external style sheet. It does the job now.

Achernar

12:38 pm on Sep 18, 2007 (gmt 0)

10+ Year Member Top Contributors Of The Month



RewriteRule ^country/([0-9]+)/$ Category.php?page=$1 [L]

Is not valid.
RewriteRule target is a filename. So no URL style parameters are allowed there ("?p1=v1&p2=v2...).
In your rule, apache tries to access a file named "Category.php?page=The$1ValueHere".

A solution could be to always rewrite to "Category.php", and have this script check its URL (it's still the one that you rewrote from) to decide what it has to do.

jdMorgan

2:59 pm on Sep 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Achernar,

Unless I'm misunderstanding your point, that substitution URL-path is perfectly-valid; Apache supports passing query strings to scripts as so-called "GET parameters." After completing the rewrite and entering the content-handler API phase, Apache itself will ignore anything in the URL-path past the "?" and execute or serve the content from the file at the path preceding it -- In this case "Category.php".

The method you describe is also supported in at least two ways; The script itself can access and parse the requested URL-path, or --on Apache 2.0 and above-- you can use AcceptPathInfo and access the 'tail' of the requested URL-path (that part of the 'friendly' URL which does not actually exist) as the variable Path_Info from within the script.

The rewrite method demonstrated here is to be preferred if you cannot or do not wish to modify the script itself. But there are several methods available to suit the needs of individual sites and Webmasters.

Jim

Achernar

11:15 pm on Sep 18, 2007 (gmt 0)

10+ Year Member Top Contributors Of The Month



that substitution URL-path is perfectly-valid;

You're correct. My memory must have it backwards. :) I stand corrected.
I've done a test and $_GET is populated with arguments from the redirection, or if none is provided, from the source URL.