Help: Mod_Rewrite

design

#1

Hi,

I am new to Apache’s mod_rewrite.

I am trying to make my urls more friendly, in which I have some url like:

/content.php?directory=dir1
/content.php?directory=dir1&page=pg1

How do I write the RewriteRule (and RewriteCond?) on my .htaccess which will function in this way:

both /dir1/ and /dir1 point to /content.php?directory=dir1

and

both /dir1/page1/ and /dir1/page1 point to /content.php?directory=dir1&page=pg1

and

/ (ie, http://mydomain.com/) point to /content.php?directory=home

both dir1 and pg1 are variables.

I need some helps from you guys.

Thank you.


sipkhoon


#2

Without knowing the backend you’re using to run your site I can’t guarantee this will work but something like:

RewriteEngine On
RewriteBase /
RewriteRule ^p([0-9]+)/dir$ /content.php?directory=dir$1 [QSA]
RewriteRule ^p([0-9]+)/dir$/page$ /content.php?directory=dir$1&page=pg$2 [QSA]

Should at least give you somewhere to start from.