PDA

View Full Version : [SOLVED] RewriteRule...


Coastal Web
03-29-2006, 06:13 AM
EDIT:
Problem solved
---


Hello fine peoples...

I was hoping that someone would be able to help me out.
I've been trying to do the following:

when a user (or bot) visits this url:

www.example.com/12345

The mod rewrite sends them to:
www.example.com/view_article.php?id=1234

---
I would also settle for:
www.example.com/articles/1234

sending users/bots to:
www.example.com/view_articles.php?mode=articles&id=1234

---

I have been using the following code:

RewriteEngine on
RewriteRule ^articles/(.*)/$ /view_article.php?mode=article&id=$1

But l get a "page cannot be found" every time. If anyone would be willing to help l would greatly appreciate it :D

thanks again,
Samantha Gram

schleppel
03-29-2006, 04:57 PM
What is the path in the 404 error? Does it say /articles/1 is not found?

Are you testing without a trailing slash? Your rule needs the trailingslash to work, adding "?" after the "/" makes it optional so it will work with or without.

If the ids are always numbers, you should use "[0-9]+" instead of ".*".

Anyway, try this:
RewriteEngine On

RewriteRule ^articles/([0-9]+)/?$ /view_article.php?mode=article&id=$1 [L]

If it doesn't work, are you sure you are able to use mod_rewrite?

Coastal Web
03-29-2006, 10:27 PM
Hello schleppel,
Thank you so much for taking the time out to assist me.

Here is what l've changed the rule to (after much more digging)

RewriteEngine on
RewriteRule (.*)/$ /view_article.php?id=$1
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
Rewritten %{REQUEST_URI} !example.php
Rewritten %{REQUEST_URI} !(.*)/$
Rewrite Rule ^(.*)$ http://somepage.com/$1/ [L,R=301]

and it seems to be working good!
Thank you ever so much for your help :D

Samantha Gram