Forum Moderators: phranque
Please forgive me if this question has been answered before. I have searched this and other forums for the past 2 days now and not found a simple solution to my problem.
I have mod-rewrite working. I have set up static linking for 2 levels deep in my site directory structure.
The problem is that I have added a 3rd level under my articles category of folders and added a rewrite rule to match. The redirect works fine, except I am unable to get the specific $1 and $2 values out when I use $_GET in my config script.
Here is my .htaccess code line:
# Three levels deep - for articles and its subcat folders..
RewriteRule ^/?articles/([a-zA-Z_^/]+)/([a-zA-Z_^/]+)$ /index.php?subj=articles&cat=$1&page=$2 [L]
So I am able to do a $_GET['subj'] and it gets the value 'articles', however, when I do $_GET['cat'] it says it doesnt exist! And if i do $_GET['page'] I get the value as 'cat.page' (it appends the cat value and the page value ignoring the / I used as a separator.
Can someone please help me understand why they are being concatenated like this?
I appreciate it
Thanks
To be clear, in your rule, mod_rewrite takes the client-requested localized URL-path on the left, and rewrites it to the server filepath on the right, copying the slash-delimited 'parameters' from the URL-path "levels" into the named query-string-parameter values.
Your rewriterule pattern looks problematic, because it accepts slashes inside the "levels." It looks like you may be trying to make an exclusive character-group and an inclusive character-group at the same time... which isn't possible.
If your intent is to accept only letters, numbers, and underscores in each "level," then I'd suggest:
RewriteRule ^articles/([a-zA-Z_]+)/([a-zA-Z_]+)$ /index.php?subj=articles&cat=$1&page=$2 [L]
RewriteRule ^articles/([^/]+)/([^/]+)$ /index.php?subj=articles&cat=$1&page=$2 [L]
If the meaning of character-group negation isn't clear, spend some time with the regular-expressions tutorial cited in our Apache Forum Charter.
If none of the above suggestions help, then I suspect that your script isn't parsing the query string properly.
Jim