Page 1 of 1

Mod Rewrite Help

Posted: Wed Aug 16, 2006 8:44 am
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.

Posted: Wed Aug 16, 2006 8:51 am
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

Posted: Wed Aug 16, 2006 9:02 am
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?

Posted: Wed Aug 16, 2006 9:04 am
by feyd
POSIX regex.

Posted: Wed Aug 16, 2006 9:04 am
by JayBird
astions wrote:Mod rewrite uses standard regex I take it?
pretty much.