Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Beginner help with modrewrite?
06-16-2010, 09:04 PM #1
- Join Date
- Apr 2008
- Thanked 0 Times in 0 Posts
Beginner help with modrewrite?
I found this rule online which seems to work for all of my pages so far:
RewriteRule (.*)/(.*)/$ /index.php?$1=$2
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!
06-17-2010, 08:35 AM #2
- Join Date
- Jan 2010
- Thanked 3 Times in 3 Posts
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.
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.Code:RewriteRule ^page/(.*)/sub/(.*)/$ /index.php?page=$1&sub=$2 [L] RewriteRule ^page/(.*)/$ /index.php?page=$1 [L]
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). It explains some basics and has a list of each of the flags too.
Lemme know if you need anymore help.