301 redirect in cakephp (moved permanently in cakephp)

301 redirect in cakephp (moved permanently in cakephp)

How to permanently 301 redirect in cakephp?
Best way for 301 redirect (permanently redirect).
301 redirect without .htaccess file.

Recently, i am working with cakephp project, and my client need to redirect all the old links to new links. As its a ecommerce website, it have the category and products but the old php developer made single page with two parameter in the query string, where one is cid which indicate the category and another one is pid which indicate the product. all the links are not seo friendly and its look like as below

N Numbers of links in the project but i show 3 example where we need to do 301 redirect from old links to new links.

 // Old Links
  productcategory.php?cid=1&pid=3      // Category and Product Page 
  productcategory.php?cid=5&pid=31     // Category and Product Page
  productcategory.php?cid=22           // Only Category Page
 // New Links 
  product/1/electronics/3/iphone      // Category and Product Page 
  product/5/games/31/play-station-4    // Category and Product Page
  category/22/beauty/                  // Only Category Page

301 redirecting is not easy and we need to workout with the rewrite rules using .htaccess file but i did it with easily in CakePHP. In cakephp 301 redirect like this is possible without .htaccess file. you need to create the productcategory.php in your webroot folder and place below code in that.

	$siteurl = "http://www.freelancephpdevelopment.com/";
	$cid = isset($_GET['cid']) ? $_GET['cid'] : '';
	$pid = isset($_GET['pid']) ? $_GET['pid'] : '';		
		case '1':
				$CategoryName = "electronics";
		case '5':
				$CategoryName = "games";
		case '22':
				$CategoryName = "beauty";
		case '3':
				$ProductName = "iphone";
		case '31':
				$ProductName = "play-station-4";
	if($cid != '' && $pid != '')
		header("HTTP/1.1 301 Moved Permanently"); 
		header("location: ".$siteurl."product/".$cid."/".$CategoryName."/".$pid."/".$ProductName);
	else if($cid != ''){
		header("HTTP/1.1 301 Moved Permanently"); 
		header("location: ".$siteurl."category/".$cid."/".$CategoryName);
	 else {
		header("HTTP/1.1 301 Moved Permanently"); 
		header("location: ".$siteurl);

After reading my article, I hope that you can resolve your 301 redirect cakephp issue. still you are facing any issue then please let me know and i will be happy to help you.

SOLVED Google fonts not working on iphone or old browsers

SOLVED Google fonts not working on iphone or old browsers

Google fonts not working in IE7, IE8, IE9.
Google fonts not working on iphone with old os
Google fonts not display on iphone and old browsers
Google fonts loading issue in old browsers

Google web fonts provide the solution to display the fonts on your web-site without install that fonts at end user’s machine, before few years if we need to apply some fonts on the web-site then that font should be installed in the user’s machine otherwise its not display but now google fonts provide the solution for that and its very simple.

you just need to load google fonts using below lines and just change the font-family in query string, then you easily apply that fonts in your web-page.

<link href='http://fonts.googleapis.com/css?family=McLaren' rel='stylesheet' type='text/css'>

Recently, i am working on that and doing testing on the iphone then i knew that this font is not working, Its working perfect in my iphone which is iphone 5 but when i checked in my friend’s iphone then its not working. he is using iphone 4 with OS 4.2.2. Later on i checked in the IE7, IE8 and some other old browser then its not working in those browser as well. I am more frustrating when i see that its working in some apple products and some windows products because its working fine with my Macs as well.

After some research i solved the issue and when you know it that you surprise that its a silly things. Its solve in some apple products and browsers using the !important keyword as shown below.

.h1{font-family:'McLaren', cursive !important;}

if you are not able to resolve it using this then go to the http://www.fontsaddict.com/ and download fonts and upload it in your css folder and add below code in your css and then its works in all machines.

@font-face {
  font-family: 'McLaren';
  font-style: normal;
  font-weight: 400;
  src: url(McLaren-Regular.ttf);

print only content of the webpage or print content div only or just prints the content of a div not the entire window

print only content of the webpage or print content div only or just prints the content of a div not the entire window

Here is the solution of how to print content only of the webpage or how to print only content in html page.

How to print content div only, not the entire window?
Use javascript:window.print() but do not print header and footer.
print specific area of the webpage using window.print() command.
only print content from html page.

Now a days, many web-site offer the “print this page” link in their web-page somewhere in header or footer. Some people never use that link and think that its same as windows print command or ctrl + p command, which is totally wrong, if you want to print some specific area of your webpage or just content area of the webpage then how you print?

if you are a web developer and you need to develop this in your web-site where user use the print link of your web-page and its print only the content of the web-page rather then the full web-page as its print like windows print feature. Normally this links are useful to those who need to print more then 1 pages of your web-site, as they are not interested in the header and footer of your web-page, they need the content only.

Its very simple to develop this feature, you need to place the below link on your web-page

		  <a href="javascript:window.print();">Print this Page </a>

Now, you need to create print.css and include it in your web-page using below link, make sure that the media is “print” not “css”


I know there is a question in your mind that what we need to write in the print.css file. below is the sample of the print.css file which is very easy to understand and implement.

			@charset "utf-8";
			/* CSS Document */

Custom Google WebSearch for your own web site

How to search the content in your own website using google services?

If you are the owner of the web-site with very good content and you are thinking to place the search feature in your site then now its very easy using the Custom google websearch API.

Custom Google websearch service API give us the option to display the google search results on our own web-site. Google will give the search result of our own site links only, so you can say that its a search feature of your own site. what you need to do is, You need to create a Custom Search Engine using your google account, then just set the below search form and the below script code on the result page. please replace the ClientID with your cx code.

Search Form
<form id="form1" name="form1" action="">  
    <input type="hidden" name="cx" value="ClientID" />
    <input type="hidden" name="cof" value="FORID:11;NB:1" />              
    <label for="Search">Search </label><input name="q" type="text" id="Search" value="Search" />
    <input class="sbmt_btn" type="submit" value="Go"/>                        
Script Code
<!-- Google Search Result Snippet Begins -->
	<div id="results_ClientID" style="background:transparent; overflow:hidden; align:left; height:1100px;"></div>
		<script type="text/javascript">
			  var googleSearchIframeName = "results_ClientID";
			  var googleSearchFormName = "searchbox_ClientID";
			  var googleSearchFrameWidth = 980;                          
			  var googleSearchFrameborder = 0;
			  var googleSearchDomain = "www.google.com";
			  var googleSearchPath = "/cse";			  
	<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
<!-- Google Search Result Snippet Ends -->

Now there are many question in your mind like,

How to change the background on custom google results page?
How to set background color with custom google results?
How to change the font style of custom google search?
Can we change the designing of the custom google search result page?

When you implement the above custom search then there is some limitation on designing part, as its a iframe provide by the google with their own css, you are not able to change any designing part in this iframe. But if you want to create your own design using the XML API where you need to work out with some programming stuff.

If you are a good programmer then its not as difficult as you think, below is the code through which you get the custom google results set in the XML format and then you can process the xml using the xml parser and display the data in your own designing templates.

	$ClientID = 'Set Your Client ID';
	$url = 'https://www.google.com/cse?cx='.$ClientID.'&client=google-csbe&output=xml_no_dtd&q='.$q.'&num=10&start='.$start;
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$getxmldata = curl_exec($ch);                

q is the parameter of your search text(search keywords),
num is the parameter to get how many results you need in the XML, maximum you can set 20 results.
start is the paramenter which indicate from where you need results set as its in the SQL statement.
ClientID is the cx code of your custom search engine

when you run the above code then you get the results set in the $getxmldata variable, Data is in the XML format, so you need to manipulate it and display as you need on your custom template.

Please visit below links for more information on XML version of the Custom Search API.