runnerjp Posted October 15, 2009 Share Posted October 15, 2009 <a href="<?php echo $puser; ?>?m=<?php=(($m-1)<1) ? 12 : $m-1 ?>&y=<?php =(($m-1)<1) ? $y-1 : $y ?>"> with the code above it displays /runnerjp?m=10&y=09 BUT if i chnage the ?m to &m then my $puser; doesnt show and all i get is /&m=.... why? Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted October 15, 2009 Share Posted October 15, 2009 the first variable in a url is prefaced by a ? the rest with & Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 15, 2009 Author Share Posted October 15, 2009 but i need it like this http://www.runningprofiles.com/members/Admin&m=11&y=2009 Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 15, 2009 Share Posted October 15, 2009 the ? tells the system to be ready for a query string and accept values thereafter delimitered with &. surely you can accomplish the same thing doing it the right way. why do you need it like that? Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 15, 2009 Author Share Posted October 15, 2009 When i do it like this http://www.runningprofiles.com/members/Admin?&m=2&y=2009 the script wont pick up the ? but when i do it like this http://www.runningprofiles.com/members/Admin&m=2&y=2009 the script picks up the month.... Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 15, 2009 Author Share Posted October 15, 2009 could it be due to my htaccess its not working RewriteRule ^([^/.]+)/?$ members/index.php?page=profile&username=$1 Quote Link to comment Share on other sites More sharing options...
cags Posted October 15, 2009 Share Posted October 15, 2009 The question mark is a regular expression special character, to match it literally you will have to escape it. That's certainly the case if you were using a PCRE function, I assume the .htaccess regex engine is similar. ^([^/.]+)/\?$ Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 15, 2009 Author Share Posted October 15, 2009 im not great on htaccess ...infact i know pritty much nothing lol my file looks liek this RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/.]+)/?$ members/index.php?page=profile&username=$1 am i right by saying i need to chnage this then? Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 15, 2009 Share Posted October 15, 2009 The question mark is a regular expression special character, to match it literally you will have to escape it. That's certainly the case if you were using a PCRE function, I assume the .htaccess regex engine is similar. ^([^/.]+)/\?$ the question mark in question, /? is stating that the new URL can end with or without a forward slash, and therefore, does not need to be escaped. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 15, 2009 Share Posted October 15, 2009 going back to your original post: with the code above it displays /runnerjp?m=10&y=09 and then you proceed to say how when you change the query string it "doesnt show". does the querystring, when formatted: /runnerjp?m=10&y=09 work for you? is there even a problem at hand? thing is, you have RewriteRule's in place, but aren't actually using them .. thus, confusing yourself in the code. reconsider your need for rewrite's. Quote Link to comment Share on other sites More sharing options...
cags Posted October 15, 2009 Share Posted October 15, 2009 Why don't you give us an example input URL and the actual URL that you wish it to link to and we can work from there. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 15, 2009 Author Share Posted October 15, 2009 dang ...sop what is the matter with it?? if i type in manually into the url address bar http://www.runningprofiles.com/members/Admin&m=6&y=2009 it works great but when i try run it via the script like this <a href="<?php echo $puser; ?>&m=<?php=(($m-1)<1) ? 12 : $m-1 ?>&y=<?php =(($m-1)<1) ? $y-1 : $y ?>"> it wont show the variable of $puser... if i saw the & with ? it will show it but the script wont pick up m= Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 15, 2009 Share Posted October 15, 2009 what does this read on the page: <?php echo $puser; ?>&m=<?php=(($m-1)<1) ? 12 : $m-1 ?>&y=<?php =(($m-1)<1) ? $y-1 : $y ?>"> copy and paste it here. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 15, 2009 Author Share Posted October 15, 2009 <a href="<? echo $puser; ?>&m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"> = http://www.runningprofiles.com/members/&m=9&y=2009 Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 15, 2009 Author Share Posted October 15, 2009 i must note if i do this <a href="<? echo $puser; ?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"> i get http://www.runningprofiles.com/members/Admin?m=9&y=2009 Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 15, 2009 Share Posted October 15, 2009 i must note if i do this <a href="<? echo $puser; ?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"> i get http://www.runningprofiles.com/members/Admin?m=9&y=2009 and what is wrong with that? that looks right .. it has your username, the month and the year all there. why doesn't that work for ya? Quote Link to comment Share on other sites More sharing options...
cags Posted October 15, 2009 Share Posted October 15, 2009 Forgive my ignorance but I still don't see your objective. You appear to be saying you wish to URL forward /members/?m=9&y=2009 to /members/index.php?page=profile&username=something which to me makes no sense at all. A standard example I would expect to see mod_rewrite employed for... Take http://www.example.com/members/john/ and redirect to http://www.example.com/members.php?name=john The main reason to use mod_rewrite is to avoid having GET attributes in the URL. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 15, 2009 Share Posted October 15, 2009 ^i'm with him .. i still don't know that i fully understand the problem at this point? like was said, what is your objective with this? Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 15, 2009 Author Share Posted October 15, 2009 ok sorry... basicly i have a calander within my profile page... and for the calander to select previous or coming up months i need to have m=? within the url so m is month and the number 1-12 represents the month needed to be selected. thats why im using m=... obviusly when a user 1st goes on the page the current month is selected within the code and m= is not needed. mrMarcus when i use that code for some reaosn my $_get wont grab the m= :S no idea why Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 15, 2009 Share Posted October 15, 2009 k, try this (untested): RewriteRule ^([^/.]+)/([0-9])/([0-9])/?$ members/index.php?page=profile&username=$1&month=$2&year=$3 this will now create a URL like so: http://www.runningprofiles.com/members/Admin/9/2009/ now, feel free to use $_GET['month'] and $_GET['year']. let me know how that pans out. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 15, 2009 Author Share Posted October 15, 2009 sent me to a this page desent exists kinda one Quote Link to comment Share on other sites More sharing options...
cags Posted October 15, 2009 Share Posted October 15, 2009 Ok, I understand that you wish to pass date and month, but it appears you've chosen to do this in the form of ?m=10&y=2009 which is fine, but where does mod_rewrite come into it? Are you attempting to merge that functionality with a mod_rewrite on username? For example trying to rewrite... http://www.example.com/members/john/?m=10&y=2009 to http://www.example.com/index.php?page=members&m=10&y=2009 EDIT: Looks like mrMarcus came to a similar conclusion... Try adding a forward slash before members to make sure the base is correct (ie RewriteRule ^([^/.]+)/([0-9])/([0-9])/?$ /members/index.php?page=profile&username=$1&month=$2&year=$3 Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 15, 2009 Share Posted October 15, 2009 my bad. try replacing what i gave you with this: RewriteRule ^([^/.]+)/([0-9]+)/([0-9]+)/?$ members/index.php?page=profile&username=$1&month=$2&year=$3 [NC,L] the [NC,L] are conditions .. NC=no case, and L=last .. so once this condition (your RewriteRule is met, the script stops searching). Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 15, 2009 Author Share Posted October 15, 2009 Ok i did that... it loads up http://www.runningprofiles.com/members/Admin fine but add http://www.runningprofiles.com/members/Admin/9 and it wont go to the page Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 15, 2009 Share Posted October 15, 2009 Ok i did that... it loads up http://www.runningprofiles.com/members/Admin fine but add http://www.runningprofiles.com/members/Admin/9 and it wont go to the page you must enter a year in the URL, ie. http://www.runningprofiles.com/members/Admin/9/2009/ each attribute of the rewrite must be met .. of course, you can create additional rewrites to accommodate different URL's. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.