PHP - Page Aliases Handled By My Cms Code, Not .htaccess Rewrite Rules?
Hello,
I'm learning how to write simple CMS and I'd like it to support page aliases. So that instead of http://www.myweb.com/?id=123 I could use http://www.myweb.com/some-page for example. I don't want to use rewrite rules in .htaccess but I'd like to do it similarly as Drupal. I understood Drupal redirects 404 page not found error to index.php and then somehow handles it. Can you advise how to do it please? Or is there any tutorial or example available? Thank you in advance! Vojta Similar TutorialsHi,
can anyone tell me what im doing wrong. below is a rewrite rule saved as .htaccess. the page loads and i dont get a 500 error but the url didnt change like it should have in the rewrite rule. The .htaccess is located in the root folder. Any idea what i'm doing wrong guys? <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^products/$ view/inventory.php </IfModule> This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=353241.0 Hi Guys, I no its only a partial PHP question but its still related to PHP... I have a URL .com/sites/0.php?Ter=144 and it takes you to a page and loads details with the id (ter) equalling 144 and displays all of 144's information... normal PHP stuff However I want to be able to put a Rewrite rule using a .htaccess (unless there is a better method!?) to get search engine frienly results. However I dont want the user to type .com/144 to bring up the Leeds branch. I want them to type .com/leeds and it bring up 144 (Leeds Branch). BranchName is the field I use for the branch name in my MySQL table. Is this possible? Also when I enter .com/sites/0.php?BranchName=Leeds that doesnt work either... Cheers, Sam 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? This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=349451.0 I was trying to refrain from posting, but its driving me mad and I am not sure what to do.
Here is the issue.
I have some rewrite rules and are making them better. But for now just need to know why this rule is giving me a page not found everytime.
Firstly, this rule works fine:
Options +FollowSymLinks This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=325281.0 Here is something i dreamt up, i know there is a way for this to work, but i'm not having any great ideas at this point. I want to be able to auto increment through the $_POST[] array data sent from a PayPal IPN. Sample return data looks like item_number1=val item_name1=val so on and so forth. The idea is: While there are $_POST item_numbers, do something with it. The loop continues until there are no more item_numbers. I don't want to use the static methods eg: explicitly defining item_number1, item_number2, ect. This is what i thought would work, but keeps failing -> the script doesn't enter the first condition: $x = 1; // set the initial item number while(isset($_POST['item_number$x'])){ $qty = $_POST['quantity$x']; while($qty > 0){ // step through each item response result, setting each item to paid $package_id = $_POST['item_number$x']; update_paid_status($transaction_id, $package_id); $qty--; } $x++; } Any Ideas? Hi, I am a php newbie, who has a page that relies on some php scripts, and to which I am trying to add a login page written in php. I took the example from he http://www.howtodothings.com/computers-internet/how-to-make-a-login-system-for-your-website Basically it consists of adding: <? require("log.php"); ?> to the top of any page I want to protect, a log.php file which performs the actions of the form, linking to a mySQL database, and a login.php file which contains the form. I have the login working fine, but it breaks one of the PHP scripts on the page that is protected. It is an upload script, called Weaverbox, based on FancyUpload. The uploads which are handled by a file called upload.php, aren't happening. The progress shows that they are being uploaded, but nothing is uploaded, and there is no success message. As soon as I remove the code from the top of the page requiring log.php all works fine again. I think I may have to add some rules/extensions to resolve this conflict, but I don't know how to go about this. Would someone be able to help me get it sorted? Thanks Nick Hey Guys, So I'm stuck on a particular line of PHP for woocommerce the code I have hear works for doing 2 levels of discount. 1 - The discount code in woocommerce coupon settings gives - 10% off for products in category named "10OFF" - Coupon settings are in the image below 2. This code here then allows the same coupon to give 15% off off products in category named "15OFF" 3. What I can't seem to work out, is how to add another layer to this, where the same coupon will give 35% off products in a category named "35OFF" I get the feeling this is something really super obvious to someone who knows more about PHP coding than myself! I've tried multiple IF statements, that breaks the whole thing. I'm confident Creating multiple Categories is the way forward. I just can't work out how to add the new categories to the code that doesn't suddenly break the whole thing again stopping all discounts being taken off each item. Any advice would be hugely appreciated! I know the Code could be a lot neater in general, but I'm really new to PHP Kind Regards to all Liam add_filter( 'woocommerce_coupon_get_discount_amount', 'alter_shop_coupon_data', 20, 5 ); function alter_shop_coupon_data( $round, $discounting_amount, $cart_item, $single, $coupon ){ //Settings// $coupon_codes = array('bigsavings'); // Product categories at 15% $product_category15 = array('15off'); // for 15% discount $second_percentage = 0.015; // 15 % // Code// if ( $coupon->is_type('percent') && in_array( $coupon->get_code(), $coupon_codes ) ) { if( has_term( $product_category15, 'product_cat', $cart_item['product_id'] ) ){ $original_coupon_amount = (float) $coupon->get_amount(); $discount = $original_coupon_amount * $second_percentage * $discounting_amount; $round = round( min( $discount, $discounting_amount ), wc_get_rounding_precision() ); } } return $round; }
Edited May 17 by liamhluk Additional info on what I've tried already In a project that I'm working on I can specify routing rules, which is somewhat similar to mod_rewrite but in PHP. It's currently set up to use full regular expressions, but it's kind of overkill. I'm trying to convert it to use routing rules similar to some of the php frameworks I've seen. The code I've written up below is working, and while it's unlikely that I would need anything more complex, I'm wondering if anyone would like to comment, offer suggestions, or offer criticisms. This little piece of code is just a part of a bigger routing class, but this is the code that I'm concerned with. Thanks.
<?php $cfg['routes'] = [ 'cars/(:any)/(:any)/(:num).php' => 'cars/$3/$1/$2', 'default_route' => 'cars/index', 'trucks/parts?year=(:num)' => 'parts/trucks/$1', 'vans/articles(:any)' => 'articles$1' ]; $uris = [ 'cars/toyota/tercel/2014.php', # /cars/2014/toyota/tercel 'default_route', # /cars/index 'trucks/parts?year=2014', # /parts/trucks/2014 'vans/articles?p=42342' # /articles?p=42342 ]; $i = 0; foreach( $cfg['routes'] as $k => $v ) { $k = '|^' . preg_quote( $k ) . '$|uiD'; $k = str_replace( [ '\(\:any\)', '\(\:alnum\)', '\(\:num\)', '\(\:alpha\)', '\(\:segment\)' ], [ '(.+)', '([[:alnum:]]+)', '([[:digit:]]+)', '([[:alpha:]]+)', '([^/]*)' ], $k ); echo '<br />' . $uris[$i] . '<br />' . $k . '<br />'; if( @preg_match( $k, $uris[$i] ) ) { echo preg_replace( $k, $v, $uris[$i] ) . '<br /><br />'; } $i++; } The following works, but I don't want to have to write 50 query statements for 50 states. How can I just write one query (using a variable I presume) and then echo the variable count each time for each state? I'm just trying to list the total number of rows for each state, that exist in the db. <? $result = mysql_query("SELECT * FROM mytable WHERE source = 'alabama'") or die(mysql_error()); $num_rows = mysql_num_rows($result); ?> href="/state/alabama/">alabama</a> (<?php echo("$num_rows");?>) <br> <? $result = mysql_query("SELECT * FROM mytable WHERE source = 'alaska'") or die(mysql_error()); $num_rows = mysql_num_rows($result); ?> href="/state/alaska/">alaska</a> (<?php echo("$num_rows");?>) <br> The above would give output such as: alabama (122) alaska (212) About a year ago I wrote a mod_rewrite in at sites htaccess file. It was to call a page that queried the database based on a unite code that was assigned to a member. If the member was assigned a code that was FL1001, the URL www.marketingteammates.com/FL1001 would bring up a page that quaried that member and displayed their database content.
In the users table of the site, it quaried the field webPageID and the information was called. It called a page webpage.php that quaried the info. The URL in the address bar still displayed www.marketingteammates.com/FL1001. Here are the lines of code in the htaccess file.
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([A-Za-z])([A-Za-z])([0-9]+)$ /webpage.php?webPageID=$1$2$3 [NC,L]I now have a second page completely different from the webpage.php. It is a page storeNumber.php and would query a field storeNumberID. This field could contain any kind of string such as Store#101, or mystore101, or #101 is my store. I tried using the same rewite rule just replaceing the webpage.php and variable with storeNumber.php and $storeNumberID. This doesn't work. It also leads me to wonder if there can even be two different pages in the mod_rewrite. How would it diferentiate one from the other. Thanks for any help in advance. Mike This topic has been rewritten to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=356324.0 (have I used that one before? I need to write these down somewhere) Not sure if this is the right place for this, but I need to be able to run some PHP code before anything loads up on the server. This is something I've been trying to figure out for some time. I've read blogs and other forums and am still not clear.
Seems that when I pass a variable that has Apostrophe's in the variable, from a form page to the submit page and insert it into the MySql DB table, it inserts OK without any / before the apostrophe.
On the other hand on the same submit page, there is a select query from another table and there are variables with apostrophe's. These queried variables keep the variables from the form page and the queried DB from inserting into a new table.
So I use mysql_real_escape_string () for the variables queried from the table to be inserted into the new table, don't use mysql_real_escape_string () on the variables passed frm the form page, and everything inserts into the new table just fine. Displays with no forward slashes.
My confusion comes from when to use mysql_real_escape_string (), stripslashes () and htmlspecialchars().
Also in the reading I was doing, it looks like mysql_real_escape_string () is being replaced with mysqli_real_escape_string (), but when I tried to use it on a variable queried from the DB something like
$username = mysqli_real_escape_string ( $s['username'] )( $s being 'foreach ( $result as $s )' from the select query. Thanks in advance for shedding any light on this. Hi I use fake IP to check if my 503 custom error page works but it doesn't?. I have another question should i stop people from hotlinking to my rss feed which is also sitemap? and stop people from hotlinking to my robots.txt?. Thanks
RewriteEngine on This topic has been moved to Apache HTTP Server. http://www.phpfreaks.com/forums/index.php?topic=351923.0 This one requires lots of up front information: I have a page, for this example that I will call page.php. It takes get parameters, and for this example I'll call the parameter "step". So I have a URL like this: page.php?step=1 This page has a form with an action of page.php?step=1. The code on the page validates the posting information. If the information is bad, it returns the user to page.php?step=1; if it is good, it takes the user to page.php?step=2 via header( "location:page.php?step=2" ). So redirection is done by relative path, not full URLs. This all works as expected. Now what I've done is set .htaccess to be HTTPS for this page, via this code: # Turn SSL on for payments RewriteCond %{HTTPS} off RewriteCond %{SCRIPT_FILENAME} \/page\.php [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] This works (initially). However, once you try to post the form, it just redirects back to the step=1 version of the page. I really don't know how or why that would be. I'm not sure how else I can explain this or what other information you may have. But it's frustrating to not get a page working in HTTPS that works in HTTP. Very odd. Any suggestions? (I don't even really know the best location to figure out when/why it's redirecting back to the original page.) This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=307024.0 |