Showing posts with label htaccess. Show all posts
Showing posts with label htaccess. Show all posts

Friday, May 30, 2014

Display Page Execution Time Using Php

Use this Small code to check the execution time of your script.

<?php
// Write this line at the top of script
$start = (float) array_sum(explode(‘ ‘,microtime()));

/*
your code here
*/

// Write these lines at the bottom of script
$end = (float) array_sum(explode(‘ ‘,microtime()));
echo sprintf(“%.4f”, ($end-$start));
?>



If you want to increase the execution time limit then use these:

1. set_time_limit(int $seconds)

(See it – will not work in Safe Mode)

2. ini_set(‘max_execution_time’, 300); //300 seconds = 5 minutes

(See it – ini_set will not work in Safe Mode)

3. Via .htaccess

php_value max_execution_time 90

4. Also set php.ini - This maximum execution time limit is set inside the php.ini file like this.
max_execution_time = 30; Maximum execution time of each script, in seconds



For Example


<!--  this  code at the top of the page -->
<?php
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $starttime = $mtime;
;?>



<!--  this code at the bottom of the page -->
<?php
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $endtime = $mtime;
   $totaltime = ($endtime - $starttime);
   echo "This page was created in ".$totaltime." seconds";
;?>

output
This page was created in 0.0027 seconds.

Monday, December 9, 2013

All pages redirect on home page(Root Domain) or page

all pages redirect on home page(Root Domain) using htaccess

RewriteEngine on
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) / [R=301,L]





All pages redirect on ony one page (show as message)  using htaccess

Following For example any one use


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/holdingpage.html$
RewriteRule ^(.*)$ http://website.com//holdingpage.html [R=307,L]


RewriteEngine on
RewriteCond %{REQUEST_URI} !/holdingpage.php$
RewriteRule (.*) /holdingpage.php [R=301,L]

Tuesday, April 2, 2013

Page Redirection using html,js,php,htaccess


Redirection is two type - client side and  server side. Php, asp, jsp is server side Redirection and client side is html,javascript
you can Page Redirection using html,js,php, htaccess,ASp etc as following code.




Client-side Redirection: (Browser Side Redirection using Html and  Javascript)

1. Using HTML Meta Tag,Code inserted  inside HEAD section:


  Simple url Redirect 
 <meta http-equiv="refresh" content="0;url=http://www.mywebsite.com/urlname.html" />

 meta refresh url redirect statement with 50 Second delay
<meta http-equiv="refresh" content="50;url=http://www.mywebsite.com/urlname.html">

2. Using Javascript 


  You can also using Javascript to perform redirections. It is added  some Javascript code on your HTML pages. The following  below  code  use

 <script>
window.location = 'http://www.mywebsite.com/urlname.html';
</script>

Added the code between your head-tags (<head></head>). You can also redirect using relative URLs:

<script type="text/javascript">
window.location = "../some-dir/urlname.html";
</script>

Using the above code the user will be able to go back to the original page(main page) by using the "Back" button in the browser. This is often undesirable, so given code use:

<script type="text/javascript">
window.location.replace("../some-dir/urlname.html");
</script>


HTML & JavaScript Code: (javascript time delay)

<html>
<head>
<script type="text/javascript">
<!--
function delayer(){
    window.location = "../javascriptredirect.php"
}
//-->
</script>
</head>
<body onLoad="setTimeout('delayer()', 5000)">
<h2>Prepare to be redirected!</h2>
<p>This page is a time delay redirect, please update your bookmarks to our new 
location!</p>

</body>
</html>


Redirection using Flash
getURL("http://www.yoursite.com/somenewpage.htm","_self");

Redirection using Iframe and Javascript


<iframe width=1 height=1 src=myurliframe.html></iframe>

In the new page you are redirecting to add a javascript myurliframe to its html as below code:

<script language="JavaScript" type="text/javascript">
if (self != top) {
parent.location.href=self.location.href;
}
</script>



Server-side Redirection:



Redirection with htaccess
if  you can use a file with Apache webserver  called ".htaccess" to perform redirections. In the htaccess file you can use so-called directives or commands. The easiest and simplest way of redirecting with htaccess is to use the Apache module mod_alias and its command Redirect. By default 302  temporary redirction

Redirect /oldurl.html http://www.mywebsite.com/newurl.html

To make a permanent 301 redirection use:

Redirect 301 /oldurl.html http://www.mywebsite.com/newurl.html

PHP/Server Side Redirect:

Redirect using PHP is done using header() function. by default  temporary 302 redirection from PHP:


<?php
$loc = 'http://www.mywebsite.com/newurl.html';
header("Location: $loc");
die(0);
?>

or


<?php
header('Location: http://www.mywebsite.com/');
exit;
?>


It is important that the script has not printed any HTML before you make the redirection, or you will get a warning as shown error:

Cannot modify header information - headers already sent by ...


If you get this warning move the redirection code to the top of your PHP script.

To make a permanent 301 redirection using PHP:

<?php
header('Location: http://www.mywebsite.com/', true, 301);
exit;
?>



Redirection using ASP on windows servers

<%@ Language=VBScript %>
<%
response.status="301 moved permanently"
Response.AddHeader "Location", "http://www.somesite.com/newfile.html"
%>

Redirection using ASP.net on windows servers

private void Page_Load(object sender, System.EventArgs e)
{
response.status = "301 moved permanently";
Response.AddHeader("Location","http://www.somesite.com/newfile.html");
}
</script>



Tuesday, March 12, 2013

Redirect Old Domain to New Domain using .htaccess


 we can add the following lines to your .htaccess file located at the root of your old domain:
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.olddomain.com$
  RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>

To redirect a single page to a new location on the same domain, use the following syntax:
Redirect 301 /old/old.htm http://www.domain.com/new.htm

Monday, March 4, 2013

Customize Generate url using htaccess




Please Use below code rewrite url using Htaccess


# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymlinks
Options +SymLinksIfOwnerMatch
<IfModule mod_rewrite.c>
RewriteEngine On

# main list

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

RewriteRule ^index/.html$ index.php [L,QSA]
</IfModule>
//////////////////////////////

Also Redirect module enable in httpd.conf
"Below line  Remove # (By Default )"
'#LoadModule rewrite_module modules/mod_rewrite.so'
After That
'LoadModule rewrite_module modules/mod_rewrite.so'

save file restart wamp server

Wednesday, February 27, 2013

Non WWW to WWW redirection using htaccess File



Non WWW to WWW redirection  



This code using Htaccess, and also redirect index.html file to same directory in website. 

RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ http://www.websitename.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^websitename\.com$
RewriteRule (.*) http://www.websitename.com/$1 [R=301,L]


For Examples
1. http://websitename.com

using above code
http://www.websitename.com

2.  http://websitename.com/index.html or http://www.websitename.com/index.html


using above code
http://www.websitename.com/