Header.php not include css file and proper links after rewriting url with .htaccess

Hi,
I’ve a little struggle with a pretty url. Here’s my .htaccess code:


RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\\.]+)$ $1.php [NC]
RewriteCond %{REQUEST_FILENAME} >""
RewriteRule ^([^\\.]+)$ home/profile.php?user=$1 [L]

and the home/profile.php


$getName = explode("/",$_SERVER['REQUEST_URI']);
$result = mysql_query("SELECT userId, name FROM user WHERE name='$getName[2]' LIMIT 1");
$num_rows = mysql_num_rows($result);

if($num_rows > 0) {
	include('header.php');
	include('index.php');
	include('footer.php');
}else{
	header('location: ../404.php');
}

The problems:

  1. I get the PRETTY URL I wanted but the header.php does not bring the style.css with it so it look just plain html page with no styling.
  2. When I click on the links it goes to e.g. www.mywebsite.com/photos.php instead of www.mywebsite.com/home/photos.php

How do I solve this.

Thanks in advance.

k0,

I can see a couple of problems with your code:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\\.]+)$ $1.php [NC]
[indent]You do NOT have to escape the dot character WITHIN a
character range definition thus you should not.[/indent]

It is just plain wrong to use the No Case flag against a RewriteRule
(on a 'nix box - okay on WinDoze but not a good practice)
because URIs ARE case sensitive.

Then, you should be using the Last flag here to break the logic
that would otherwise tie this RewriteRule to the next (albeit
Apache ignores the implied AND in this case).[/indent]

RewriteCond %{REQUEST_FILENAME} >""
[indent]This will always be true as it includes the path
to the domain which can't be null.[/indent]
RewriteRule ^([^\\.]+)$ home/profile.php?user=$1 [L]
[indent]This ASSUMES that all URIs without a dot character
(file extension) will be a valid user value. IMHO, this is NOT
a good assumption and will likely cause problems UNLESS your
profile script has the intelligence to "dodge the bullet."

To your problem, though, this RewriteRule changes directory
level so all relative links will be off one level. Have a read of
my signature's tutorial for more information about this as well
as the two options you have to "dodge this bullet."[/indent]

if($num_rows > 0) {
	include('header.php');
	include('index.php');
	include('footer.php');
}else{
	header('location: ../404.php');
}

I’m not sure what else you’ve done (header, index and footer shouldn’t be found IF they’re in the home subdirectory) so this code is looking for 404 above the root directory. you can resolve this (404) problem by making it an (internal) absolute redirection (eliminate the …).

Regards,

DK