views:

22

answers:

2

Good morning.

I currently have this little rule in my .htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^brochure/([0-9]+)$ /brochure.php?cat_path=$1 [L]

(i'm just using numbers for example here, will be category names later.)

This redirects perfectly, but when it does, everything I have in directories now fail (css, js, images, includes etc)

I understand the issue (it's throwing the directory structure off).

Changing the rule to this solves the images, css and JS problem.

RewriteRule ^([0-9]+)$ brochure.php?cat_path=$1 [L]

But it's not what I want really.

What's the correct way to do url rewrites and maintain directory structure?

Thankyou, I have search for through previous questions, but couldn't find a suitable answer.

+2  A: 

You hve to use absolute paths, or relative to the webroot, like:

<img src="http://example.com/image.gif" alt="" />
<img src="/images/image.gif" alt="" />

If you know that your images are always a directory up, this will be an option too:

<img src="../images/image.gif" alt="" />
Lekensteyn
for everything? including all my js, css, and php files? I thought there would be a more efficient way of doing this. :(
shane
The *inefficiency* is not in using absolute paths, it's in using relative paths. That's something you'll have to fix sooner or later.
Álvaro G. Vicario
Ok thanks for the advice. I can see now where using relative paths is going to make my life harder in the future. Thanks guys.
shane
A: 

Although I honestly recommend Lekensteyn's answer, there's also another solution. Your mod_rewrite rule basically moves /brochure.phpcat_path=123 to /brochure/123. You can simply fix your relative URLs and set the correct path. Your must understand that these paths are parsed by the browser so the actual server file system structure has nothing to do with it.

E.g.: css/style.css will become ../css/style.css

Álvaro G. Vicario