PHP - .htaccess Querystring
I have the current rule in my htaccess
RewriteRule ^catalogue/([a-z0-9-]+)/([a-z0-9-]+).php$ catalogue/item.php?id1=$1&id2=$2 [L] however whenever i type in the browser /catalogue/computers/cases.php and then change the category to a category not in my database it still shows the item.php page but without any data - blank page. How do you redirect this to a 404 or do I just write a script that if no records are found in the database redirect to the main catalogue page? Similar TutorialsHi: How can I build a querystring (or whatever I need to do to solve my issue) to pull in the month and year? Meaning: I have this link: Code: [Select] Entertainment.php which goes to a dynamic calendar, which works fine except it does not show the events because I think it replies on getting the current month and year. When I click on a "Next Month" and the click back to the current month, the URL is: Code: [Select] Entertainment.php?month=4&year=2011 and the events then display properly in the calendar. How do I properly build a URL for this? The calendar code looks like this: Code: [Select] <?php ob_start(); $today = date("M Y"); ?> ... <head> <script> function show_evt(m,y,day){ location.href = "<?=$_SERVER['PHP_SELF'];?>?month=" + m + "&year=" + y + "&day=" + day; } function goLastMonth(month, year) { if(month == 1) { --year; month = 13; } document.location.href = '<?=basename($_SERVER['PHP_SELF']);?>?month='+(month-1)+'&year='+year; } function goNextMonth(month, year) { if(month == 12) { ++year; month = 0; } document.location.href = '<?=basename($_SERVER['PHP_SELF']);?>?month='+(month+1)+'&year='+year; } </script> </head> ... <p> <?php $date =time (); $day = (isset($_GET['day'])) ? $_GET['day'] : date('d', $date); $month = (isset($_GET['month'])) ? $_GET['month'] : date('m', $date); $year = (isset($_GET['year'])) ? $_GET['year'] : date('Y', $date); $first_day = mktime(0,0,0,$month, 1, $year); $title = date('F', $first_day); $day_of_week = date('D', $first_day); switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } $days_in_month = cal_days_in_month(0, $month, $year); ?> <table class="tableClass"> <tr class="field-bg-color"> <th class="eventLeftArrow"><a href="javascript: void(0);" onClick="goLastMonth(<?php echo $month . ", " . $year; ?>)"><<<</a></th> <th colspan="5" class="eventHeader"><?=$title. " " . $year;?></th> <th class="eventRightArrow"><a href="javascript: void(0);" onClick="goNextMonth(<?php echo $month . ", " . $year; ?>)">>>></a></th> </tr> <tr class="calDates"> <td>S</td> <td>M</td> <td>T</td> <td>W</td> <td>T</td> <td>F</td> <td class="lastOne">S</td> </tr> <?php $day_count = 1; ?> <tr> <?php while ( $blank > 0 ) { ?> <td> </td> <?php $blank = $blank-1; $day_count++; } $day_num = 1; while ( $day_num <= $days_in_month ) { $sql = "select count(calName) as evt_count from calTbl where calDate ='" . $month . '/' . $day_num . '/' . $year . "'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ if($row['evt_count'] >= 1){ ?> <td align="center" style="cursor:hand;cursor:pointer;background-color:#FF6A6A;text-align:center;" onclick="show_evt('<?=$month;?>','<?=$year;?>','<?=$day_num;?>');"> <div class="brown-bg-color cal-head-text white-text bold-text"><?=$day_num;?></div> <?php $sql = "select * from calTbl where calDate ='" . $month . '/' . $day_num . '/' . $year . "'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ ?> <a href="<?=$_SERVER['PHP_SELF'];?>?month=<?=$month;?>&year=<?=$year;?>&day=<?=$day_num;?>"><?=$row['calName'];?></a></br> <? } }else{ ?> <td> <div class="brown-bg-color cal-head-text"><?=$day_num;?></div> <?php } } ?> </td> <?php $day_num++; $day_count++; if ($day_count > 7){ ?> </tr><tr> <?php $day_count = 1; } } while ( $day_count >1 && $day_count <=7 ) { ?> <td> </td> <?php $day_count++; } ?> </tr></table> <?php if(isset($_GET['day'])){ $sql = "select * from calTbl where calDate ='" . $month . '/' . $_GET['day'] . '/' . $year . "'"; $result = mysql_query($sql); echo '<table class="data-table-class">'; echo '<th>Event Name</th><th>Event Desc</th>'; while($row = mysql_fetch_array($result)){ echo '<tr><td>'. $row['calName'] . '</td><td>' . $row['calDesc'] . '</td></tr>'; } echo '</table>'; } ?> <div class="myClear"></div> <?php ob_flush(); ?> </p> Can anyone help me out? This is the last part and I am good to go! Thanks! Anyone know how i can remove a querystring from url. Example URL: http://www.mysite.com/?id=1 I am writing a script that needs to read in the ID from the URL. But once have got the information i would like to remove it from the URL and just display http://www.mysite.com but still be able to use the ID to query my database. Any ideas??? Greetings experts, Please forgive me for this cheap question. I have got a calendar of events and displays events for 7 departments. For each department, we would like the calendar to display events specific to that department. The way I am thinking about doing this is to grab the department from the url and compare it with the department on the db for which events is inserted into the db with. If there is a match, then display the events for that department. Something like: $tquery = "select * from ".$EVENTS_TB." where ".$EVENTS_TB.".month='".$smmonth."' and ".$EVENTS_TB.".year='".$smyear."' and ".$EVENTS_TB.".deptid='deptFromQueryString' " ; The problem that I have is that I don't in php, how to capture the querystring from url. For instance, assume this is the url: http://www.domain.com/departName. DeparmentName represents the department value. How do I capture the query above? Thanks so much.
I've inherited some PHP code that is trying to save a querystring to a variable: $from_url = ''; if ((isset($_GET['from'])) && ($_GET['from'] != '')) { $from_url = $_GET['from']; }
I am working with a fellow who runs an eCommerce shop. The transaction resolution comes in on a querystring.
I do not yet know what web server software is being used, nor if any security appliance/software is installed.
One of the values in the querystring starts with the @ character.
We know the web server gets this as there entries in the web server's access log that shows thing value is present.
It is not available in PHP's $_GET array.
We are trying to get an idea of where this value, and it's key, is getting discarded.
Is there a known problem with (actual server software being used not yet known) web server software discarding a key/value if the value has the @ character in the querystring?
Hi I have a problem i need some help with, when passing values from my Results page to my Details page through a URL is the Querystring different because i have INNER JOINED 2 tables? This is my Querystring <a href="DetailsPet.php?id=<?php echo $row_ResultsRS['id']; ?>">Details</a></td> i have 2 tables (petdata and customerdata) and there INNER JOINED using the 'id' But its not passing on the values, and just shows the 1st results in database all the time. Im only just learning Php, but would i be right in thinking it to do with the 'id' as this is what joins the 2 tables. Do i have to state which 'id' to use? if so how do i do it? Thanks willo Hi: I am trying to pass/request a Variable/QueryString from one page to another, but it isn't working. Seems like it would be simple, so maybe I am overlooking the obvious. I have the 1st page: Code: [Select] <a href="NewCity.php?abbr_state=<?php echo $abbr_state ?>">Insert New City</a> Writes the URL properly - CityList.php?abbr_state=CT The 2nd page: Code: [Select] <?php $abbr_state = $_REQUEST['abbr_state']; ?> <form> State: <input type="text" name="abbr_state" value="<?php echo $abbr_state; ?>" readonly=""/><br /> </form> But it does not get the variable/QueryString for "CT" and add it to the form field (it's not the "readonly" causing it). Why? What did I miss? Hi, how to let php read the url in folder form instead of querystring? e.g. www.example.com/index.php?post=123 www.example.com/post/123/ both is actually directed to the same page - index.php, but how to make it read like a folder when the physical path doesn't really exist? the ultimate goal is to let the user select to date range (begin date in DD-MM and enddate in DD-MM), pass this through php file with ajax and query it against the registered date (stored as a datetime), however i'm already running problems catching the values of minDate and maxDate. Can sombody tell me what's wrong please? Code: [Select] if (document.getElementById('brdat_dag').value != ''){ var minDag = document.getElementById('brdat_dag').value;} if (document.getElementById('brdat_maand').value != ''){ var minMaand = document.getElementById('brdat_maand').value; } var minDate = date ('Y-m-d H:i:s', mktime (0,0,0,minMaand,minDag.value,date('Y', time()))); var queryString = "?postcode=" + postcode + "&provincie=" + provincie + "&aland=" + aland + "&gland=" +gland +"&minAge=" + minAge +"&maxAge=" + maxAge + "&sex=" + sex; + [color=red]"&minDatum=" + minDatum;[/color] Hi can someone help me i have this .htaccess code
Supposed i have RewriteRule ^([a-zA-Z0-9-z\-]+)/([^.]+)/([a-zA-Z0-9-z\-]+)$ index.php?Active=$1&PostID=$2&PostName=$3 [L]
this line wont work ##RewriteRule ^([a-zA-Z0-9-z\-]+)/([^.]+)$ index.php?Active=$1&PostCell=$2 [L] so i commented it
i need to make them both work for pretty urls Options -Indexes Options +FollowSymLinks -MultiViews RewriteEngine On ErrorDocument 404 /404.html ErrorDocument 401 /404.html ErrorDocument 403 /404.html ErrorDocument 404 /404.html ErrorDocument 500 /404.html RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} /(.*)/$ RewriteRule ^ /%1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{DOCUMENT_ROOT}/$1 -f RewriteRule ^[^/]+/([^.]+\.(?:js|css|jpe?g|png|gif))$ /$1 [L,R=301,NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-zA-Z0-9-z\-]+)/?$ index.php?Active=$1 [L] ##RewriteRule ^([a-zA-Z0-9-z\-]+)/([^.]+)$ index.php?Active=$1&PostCell=$2 [L] RewriteRule ^([a-zA-Z0-9-z\-]+)/([^.]+)/([a-zA-Z0-9-z\-]+)$ index.php?Active=$1&PostID=$2&PostName=$3 [L] Thank you in advanced. Edited May 27, 2020 by azumicaHi, Was woudering if someone could help? I would like to stop people accessing a folder (web directory) on my domain using the .htaccess. However the folder contains scripts in it that i use thererfore a redirect away from that folder does not work. can you help? Hi how can I make this URL clean http://localhost/?Active=View&PostCategory=1 i want to remove the ?,&, = make them into / this is the php code that manipulate the link <?php Class ControlURL{ public static $_page = "Active"; public static $_folder = Web_Body; public static $_params = array(); public static function cPage() { if(isset($_GET[self::$_page])){ return $_GET[self::$_page]; }else{ return 'index'; } } public static function getPage() { $page = self::$_folder.DS.self::cPage().".php"; $error = self::$_folder.DS."error.php"; if(is_file($page)){ return $page; }else{ return $error; } } }
Hi people i have this link http://localhost/ViewCategory/PHP my problem is everytime i put / from PHP/ it will redirect me to Access forbiden andd return me this http://localhost/C:/xampp/htdocs/index.php?Active=ViewCategory&PostCategory=PHP/
how to fix it this is how my htaccess code
Options -Indexes RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{DOCUMENT_ROOT}/$1 -f RewriteRule ^[^/]+/([^.]+\.(?:js|css|jpe?g|png|gif))$ /$1 [L,R=301,NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-zA-Z0-9-z\-]+)/?$ index.php?Active=$1 [L] RewriteRule ^([a-zA-Z0-9-z\-]+)/([^.]+)$ index.php?Active=$1&PostCategory=$2 [L]
Hello everyone,How can i change the url when I am navigating from one page to another. for example if the existing url is like "www.example.com/product.php?name=xyz&q=service" ,I want to change it to "www.example.com/product/name/xyz/q/service" But I dont want to use .htacces. How can I do it using php functions only? I need help to shorten the following url in apache .htaccess
example.com/index.php?q=1&w=2
if possible, the url that i would like is...
example.com/index.php/1/2
or better yet...
example.com/index/1/2
Hi all
I am using the following rewrite rule
RewriteRule ^news([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ news.php?id=$1&identifier=$2when I use the link generated I get a 404 Not Found but if I go the genuine URL e.g. www.jasondoyle69.com/news.php?id=[id]&identifier=[identifier], then the page is displayed correctly. My question is, how do I do the rewrite rule for this, where there two php variables? This topic has been moved to Apache HTTP Server. http://www.phpfreaks.com/forums/index.php?topic=306351.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=356252.0 I'm attempting to rewrite my urls but don't seem to be getting it to work. I've tried: RewriteEngine On RewriteRule /(.*)/(.*)/$ listings.php?ident=$1&facility=$2 And I've also tried: RewriteEngine On RewriteRule ^([^/\.]+)/([^/\.]+)?$ listings.php?ident=$1&facility=$2
Any suggestions? |