|
-
Jul 3rd, 2009, 10:48 PM
#1
Thread Starter
Lively Member
[RESOLVED] mod_rewrite
Heyas, so I'm attempting to teach myself mod_rewrite in htaccess. I've been attempting to create a url rewrite like WP uses, but with just Parent/Child. So far I have:
Code:
RewriteRule ^directory/(.*)/$ parent.php?parcat=$1
RewriteRule ^directory/(.*)/(.*)/$ child.php?parcat=$1&subcat=$2
The parent works, but whenever I attempt to call the sub (child), it attempts to use parent instead.
I've tried multiple ways including changing all names, setting different virtual dir's, setting the regex to [A-Za-z] (There's no numbers, so [0-9] wouldn't need to be added), and calling them both through the same page. All to no avail *sigh*...
Any help would be greatly appreciated.
Thanks in advance.
Please use the search function prior to posting a question and see if someone's already answered it.
-If I helped you, please rate me, as I'd do the same for you =)
-Remember to select the Resolved option for your post when you've gotten the answers you need.
-
Jul 4th, 2009, 02:07 AM
#2
Re: mod_rewrite
I think your problem here is that .* means "any character, as many times as possible." So, it works in your first one because you're only getting one group; it doesn't work in the second one because it can never get to your second group: the first group is grabbing everything. Try this...
Code:
RewriteRule ^directory/([^/]*)/$ parent.php?parcat=$1
RewriteRule ^directory/([^/]*)/([^/]*)/$ child.php?parcat=$1&subcat=$2
[^/]* means "any character except for /, as many times as possible." When it gets to a /, it should stop grouping. At least I think that's right... I don't always gets these right on the first try.
-
Jul 4th, 2009, 11:43 AM
#3
Thread Starter
Lively Member
Re: mod_rewrite
Awesome. Thanks, Sambo! I was looking at some tutorials for Regex, and didn't see that anywhere. Any recommendations for a good tut for this by chance?
Please use the search function prior to posting a question and see if someone's already answered it.
-If I helped you, please rate me, as I'd do the same for you =)
-Remember to select the Resolved option for your post when you've gotten the answers you need.
-
Jul 4th, 2009, 01:00 PM
#4
Re: [RESOLVED] mod_rewrite
Regex is still a topic that I'm not entirely confident with, myself. It doesn't help that there are variations to it based on which context you're in. But, for htaccess-flavored regex, I've bookmarked and returned to this page often for a reference. It's got a lot of info and examples.
-
Jul 14th, 2009, 07:16 AM
#5
Fanatic Member
Re: [RESOLVED] mod_rewrite
Hi neato, for regex tutorials you should see - http://www.regular-expressions.info/
@SambaNeko
Thanks for that solution...
Prior to now, if i encounter such problems, what i do is something similar to below
Code:
RewriteRule ^directory/(.*)/(.*)/$ child.php?parcat=$1&subcat=$2
RewriteRule ^directory/(.*)/$ parent.php?parcat=$1
so it'll always process this
Code:
RewriteRule ^directory/(.*)/(.*)/$ child.php?parcat=$1&subcat=$2
before this
Code:
RewriteRule ^directory/(.*)/$ parent.php?parcat=$1
thanks for that eye opener
Last edited by modpluz; Jul 14th, 2009 at 07:29 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|