Mod Rewrite not working 100%

sublimer's picture

They have: 41 posts

Joined: Aug 2006

First off, I use 1and1 servers...

Heres what I have, and what I want...

What I have...

http://www.sublimestylee.com/news/?id=500

What I want...

http://www.sublimestylee.com/news/500/

This may seem like an easy fix, but I have been playing with it for hours and I am stumped.

Here is the code...

RewriteEngine on
RewriteBase /pages/
RewriteRule news_story_display\.php$ /news/$1 [R,L]
'

It may seem like I just need to add ?id= after the .php part in the 3rd line, but it doesn't work. If I include it so the code looks like...

RewriteEngine on
RewriteBase /pages/
RewriteRule news_story_display\.php?id=$ /news/$1 [R,L]
'

The URL's are now like the original, before I edtied my .htaccess file and display like...

NOTE: I have used escape characters infront of the ? and such with no luck either.

http://www.sublimestylee.com/pages/news_story_display.php?id=500

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

This should do it:

RewriteEngine on
RewriteRule ^news/([0-9]+)$ news/?id=$1 [L]
'

sublimer's picture

They have: 41 posts

Joined: Aug 2006

Nope, I implemented that and there is no difference in the URL, they are still like...

http://www.sublimestylee.com/pages/news_story_display.php?id=42

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

sublimer;227481 wrote: Nope, I implemented that and there is no difference in the URL, they are still like...

http://www.sublimestylee.com/pages/news_story_display.php?id=42

The original URL will still work. When you use the rule that I posted, http://www.example.com/news/?id=123 will work in addition to http://www.example.com/news/123

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

This is little more than an edited copy/paste:
RewriteRule ^news/(.*)$ news_story_display.php?id=$1 [L,QSA]'

I blagged it from Drupal (as it's ReWrite malarkey is pretty similar to what you're doing). Give it a try; not sure about the QSA rule at the end, according to the Apache docs:

Apache docs wrote: 'qsappend|QSA' (query string append)
This flag forces the rewriting engine to append a query string part in the substitution string to the existing one instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.

*** EDIT ***
Is that 404 page your doing, or the hosts?

a Padded Cell our articles site!

akopayan's picture

They have: 106 posts

Joined: Nov 2006

I think it's the host.

tummy's picture

They have: 121 posts

Joined: Mar 2007

Thinks it's the host.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.