...

View Full Version : Beginner help with modrewrite?



pankirk
06-16-2010, 09:04 PM
I found this rule online which seems to work for all of my pages so far:


RewriteRule (.*)/(.*)/$ /index.php?$1=$2

basically this takes my pages that look like this: url.com/index.php?page=index,

and turns them into this: url.com/page/index/

This is great and is exactly what i'm looking for, but I can't seem to figure out what to do when I have multiple arguments in the url.

For example, if I have this: url.com/index.php?page=index&sub=subpage.

can someone please direct me in the right direction to form that url into this: url.com/page/index/sub/subpage/

thanks a lot!

Zoic
06-17-2010, 08:35 AM
You would simply need to add another rule for that.

I've adjusted your first line so that its more specific on what it should accept and what to do with it because just using (.*) will match every character and any number of characters, which can sometimes give you undesirable results.


RewriteRule ^page/(.*)/sub/(.*)/$ /index.php?page=$1&sub=$2 [L]
RewriteRule ^page/(.*)/$ /index.php?page=$1 [L]

Just to go over it, the ^ character means that this is the start of the string. I put [L] at the end of both lines to tell apache that if the URL requested matches this, stop going through the rules and use this one.

If you want to learn more about mod_rewrite, I posted a tutorial on my site about it (How to make SEO Friendly URLs using mod_rewrite (http://www.molt3n.com/tutorials/view/18/how-to-make-seo-friendly-urls-using-modrewrite/)). It explains some basics and has a list of each of the flags too.

Lemme know if you need anymore help. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum