Cant figure out mod rewriting

I have my url as

http://www.example.com/content.php?whereto=123 or http://www.example.com/content.php?whereto=about

and I am trying to re-write them to

/content.php/123 or /content.php/about

This is what I have for my first one >>


#ADDEXPIRES
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType application/pdf A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/plain A2592000
ExpiresByType text/css A17200

RewriteEngine on
RewriteRule ^/content/([0-9]+) content.php?whereto=$1

but when I try I just get a page not found and nothing else.

where am I going wrong please.

Thanks

Actually! I have changed it to >>


#ADDEXPIRES
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType application/pdf A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/plain A2592000
ExpiresByType text/css A17200

RewriteEngine on 
RewriteRule ^content/([0-9]+) content.php?whereto=$1 

it now finds the page ok BUT no images or css are loaded! where am I going wrong please.

Chris

The problem will be that the file is trying to call a CSS file and that link is being run through the same ReWrite rules as the filepath.

You can solve this problem by using the “root link” format, eg <link rel=“/styles/sheet1.css”> where that first / tells the browser to start in the root folder, regardless of what folder the current file is in.

Hi.

Yup. That sorted that problem out and I am able to see the re-written pages ok.

My next problem is I have a couple of other different url structures that need re-written - do I just go ahead and put them in one after another?

I am struggling to think I how would re-write these

[noparse]http://www.example.com/index1.php?whereto=coop[/noparse]
[noparse]http://www.example.com/index1.php?act=display&displayWhat=93[/noparse]

What would your suggestion be.

Thanks for your help
Chris

Chris,

You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.

Stevie - what does that mean? Your comment would be valid if the css file name started with one or more digits but …

Regards,

DK

Sorry, I was looking at the examples, where Chris used “about” as the file name without any digits - I just assumed that the code was right for the examples given :blush:

The served file is /content.php, but accessed through /content/ so all support files don’t work anymore (wrong path, if the support URLs are relative).
So, Stevie’s comment is indeed valid, as is his solution (use absolute paths instead of relative paths) :slight_smile:

(an alternative would be to use the html <base> tag)

It was :slight_smile: