Weird redirections

Hey guys,

My .htaccess sends all page requests to the index.php - I am stripping the extension off filenames, so, all of my URL’s are like www.abc.com/about/ instead of www.abc.com/about.php

The issue I am having is that it appears that with this, it is fooling either the script or the webserver thinking we’re in a different directory, so, although the content loads fine (the page content) items like the stylesheet which is embeded and images do not load. On closer inspection, it is now looking for the stylesheet in abc.com/about/style/main.css instead of abc.com/style/main.css - I really have NO IDEA where to look and my .htaccess knowledge is EXTREMELY limited.

I have attached below the rewriteconditions and rule and also the embedded url so that you can have a look at what I am doing wrong :slight_smile:


# Rewrite all filenames to mod rewrite filenames
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [NC,L]

// AND THE STYLE:
<link rel="stylesheet" href="css/main.css" media="all" />

I would obviously like to avoid using full url’s like www.abc.com/css/main.css when embedding content, so any help will greatly be appreciated

This is kind of off topic, so apologies for that, but an easier way to have URLs like mysite.com/about/ is to have an /about/ folder with an index.php file in it. That’s probably easier than having to set up Apache redirects. (It wouldn’t help with the CSS files, but that doesn’t really matter, as those links aren’t really public anyway.) Just thought I’d mention this anyway. :slight_smile:

Hey Ralph,

Thanks for your reply. In principle I understand this and see the proposed solution, however, its not really a consistant solution for long term growth of a project. Whats just very frustrating is that one knows its possible, yet, there is so little resources which can effectively help you.

It almost feels like each project has his own htaccess devils and getting past it is a nightmare. Anyways thanks for your proposed solution, but I hope someone else can assist here as well :slight_smile:

Yeah, sorry I can’t help more (I should really keep out of here! :lol: )

Just in case you haven’t seen it yet, it’s worth reading through this sticky thread:

It’s really handy, and I keep looking back at it with the intention of studying it in detail.

Anyhow, I’m sure some knowledgeable people will pop in soon to give you a proper answer. :slight_smile:

What’s happening is that relative links a broken because you’re intoducing “directories” (even if they’re fake, the browser doesn’t know that).

Check out the section “Relative Links Are Missing!” here Apache’s mod_rewrite