PHP - .htaccess Not Working For Rewrite Rules
Hi,
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> Similar TutorialsHello, 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 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 Hi, I have the following file structure /.htaccess /index.php /displaypage.php All files are on root. I have following written in .htaccess file Options FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z0-9-]+)$ displaypage.php?page=$1 [NC,L] I have following written in displaypage.php echo $_GET["page"]; Now when I run http://localhost/ then it shows index.php page which is correct. If I run http://localhost/something then it shows a blank page. Previously it used to display that "page" variable on screen. mod_rewrite is enabled and I am using Windows with XAMPP. What am I doing wrong? Thanks Hi all. I dont knw why I still can't get it right after many tries. The .htaccess just can't locate the .bypassed file. On my domain I created a folder called hidden in my web root and this is my authfile path: /www/hidden/.htpasswd but still no show. pls what am I missing here. I even tried it on localhost: /www/my_folder/hidden/.htpasswd same no show. help pls. thanks i have recently bought a new samsung netbook so i downloaded the latest version of WAMP to develop my site. However when i run my site i get the internal server error associated with the htaccess file. The thing is that this file works on my desktop pc. The version i have of WAMP on this netbook is newer than the one i have at home, socould this be the problem? i can post the contents of the htaccess file if you think it will help, its just a lot of rewrite rules. Thanks 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++; } This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=307024.0 I want to rewrite this url
site.come/info.php?country=america&state=colorado&city=denver hello friends, that would help me alot , if i've 2 code all are of if and else code 1 $r = $_SERVER['HTTP_REFERER']; if (stripos($r, $refere) !== false) { echo "good"; }else{ echo "bad"; } code 2 if($line[hits] >= $limited){ echo "bad"; }else{ echo "good"; } both are 2 codes where the user should pass before it show good how then it be 1 code not 2 ( if x if y else y2 else x2 ) it like double sandwich I am having trouble rewriting a url, I have taken on a project that to rebuild a site that is over 7 years old and the current url structure is "http://www.mysite.com/?page=home" this i find crazy who uses "?page=" anyway am now creating the site again using a better structure of http://www.mysite.com/home.htm my problem is that the owner of the site has good google results with the current urls but wants them changing, and for the old ones to work too, i am trying to do this with .htaccess but the "?" in the url is causing massive problems with internal server errors. can anyone help me please it driving me nuts. Thanks in advance This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=318852.0 This topic has been moved very early in the morning to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=359281.0 Say my URL is http://www.example.com/catalog.php?category=hats&prodID=53 and I use Mod-rewrite to make it http://www.example.com/catalog/hats/53/ Can I still use $_GET['category'] to get the parameters? If so, how? Hi, I've a problem modifying the code which send parallel requests to get the status from getstatuses().I've two functions say public function getStatuses($idList) { } public function getid($id) { $status = array(); foreach ($id as $idList) { $status[] = $this->getStatuses($idList); } return $status; } the above getid() function sends the synchronous requests to the getstatuses() function and get the status back one after another.If you need to make 5 HTTP requests and each call takes a second, your app is delayed at least 5 seconds.Now,i want to rewrite the code(if possible two functions)that speeds up the results by sending all the requests and getting back the statuses at once.Something,other friends have developed is to reverse the getstatuses() and getid() functionality.Can anybody help me writing this code Thanks |