Mod Rewrite Help

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Mod Rewrite Help

Post by Benjamin »

I need a rewrite statement that will take an url such as this..

domainname.com/category/name/page_1.html

and allow me to extract the category, name and page number in a file called something like domainname.com/view.php. The only catch is that there are probably going to be other rewrite statements, so the url will need to have some sort of unique identifier, possibly page?

I don't know how to write mod rewrite statements. I have some code..

Code: Select all

RewriteEngine On
RewriteBase /
RewriteRule ^somepage/(.*)\.html somepage.php?rewrite=$1 [L]
Which will take http://yoursite.com/somepage/id-20/name-funny.html and allow it to be parsed by php..

Code: Select all

if( $_GET['rewrite'])
{
    $request = $_GET['rewrite'];
    mod_rewrite( $request, '/', '-' );
# if you have register_globals enables uncomment the following
#    extract( $_GET, EXTR_OVERWRITE );
}
But I don't want the variable name (ie id and name) to be in the url.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Mod rewrite isn't my strongest skill, but try something like this

Code: Select all

RewriteRule ^([A-Za-z0-9]+)/page_([0-9]+)\.html?$ view.php?cat=$1&page=$2
EDIT: i'm probably well off with that actually
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Hey thank's a lot. That looks like it would work but I need 1 more variable in there for the /category/. Mod rewrite uses standard regex I take it?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

POSIX regex.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

astions wrote:Mod rewrite uses standard regex I take it?
pretty much.
Post Reply