Thursday, 9 April 2015

Htaccess interview Questions and Answers for fresher and experienced

Htaccess interview Questions and Answers for fresher and experienced



Question: How to redirect http to https?
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]


Question: How to redirect http:// to https://www?
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]


Question: How to redirect non-www to www ?
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


Question: How to redirect all pages to newdomain?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com [R=301,L]


Question: What is meaning of R & L flag in htaccess?
htacces R flag causes a HTTP redirect to be issued to the browser and 301 means its permanent redirect.
htaccess L fag causes to stop processing the rule set, if the rule matches, no further rules will be processed.
Also we can set more than 2 flags in brackets []
More flags


Question: How to redirect homepage to another Website?
Redirect / http://www.web-technology-experts-notes.in/


Question: How to redirect to another directory within same domain?
Redirect /olddir /newdir


Question: How to set environment in .htaccess?
SetEnv APPLICATION_ENV development


Question: How to set the php config variables in .htaccess?
php_value upload_max_filesize 32M


Question: How to set display_error off in .htaccess?
php_flag display_errors off
php_flag display_startup_errors off


Question: How to block few IP address?
order allow,deny
deny from xxx.xxx.xxx.xxx #specify a specific address
allow from all


Question: How to redirect to error/404.html when 404 errors comes?
ErrorDocument 400 error/404.html


Queston: How to set the caching for javascript/images/css?
ExpiresActive On
ExpiresByType application/javascript "now plus 3 day"
ExpiresByType application/x-javascript "now plus 3 day"
ExpiresByType image/jpg "now plus 1 week"
ExpiresByType image/jpeg "now plus 1 week"
ExpiresByType image/png "now plus 1 week"
ExpiresByType image/pjpeg "now plus 1 week"
ExpiresByType image/gif "now plus 1 week"
ExpiresByType text/css "now plus 3 day"


Question: what is meaning of 301, 302, 400, 401, 403, 404 and 500 error codes?
301 - Permanent movement
302 - Temporary movement
400 - Bad request
401 - Authorization Required
403 - Forbidden
404 - Page Not Found
500 - Internal Server Error


Question: How does RewriteBase works in .htaccess?
It is used to set a base URL for your rewrites rules.
RewriteEngine On
RewriteBase /~new/


By setting the RewriteBase there in htaccess, you make the relative path come off the RewriteBase parameter.


Question: How to create Subdomains on the fly using .htaccess?
for this, you have set the virtual host
Follow the following steps.
Step 1: Create a wildcard DNS entry
*.domain.com.   3600  A  127.0.0.1

Step 2: Setup the Virtual Host, in vhost file.

<virtualhost> DocumentRoot "E:\wamp\www\myproject" ServerName myproject.domain.com <directory myproject="" wamp="" www=""> AllowOverride All Order allow,deny Allow from all </directory> </virtualhost>

Step 3: Now write your all codes in in Document Root path i.e.E:\wamp\www\myproject
Step 4: Done, now you can access with myproject.domain.com


Question: Do i need to restart the apache after chnages in .htaccess?
No,


Wednesday, 8 April 2015

PHP MySQL interview questions and answers for experienced

PHP MySQL interview questions and answers for experienced




Question: What are 3 different ways to connect  with MySQL?
Following are 3 API with which we can connect to MySQL
1. MySQL
2. MySQLI
3. PDO

We should use MySQLI because MySQLI is imporoved version of MySQL and it have lot of functions which are absent in MySQL.


Question: What is the best collation to use for MySQL?
utf8_general_ci: It is used for fast sorting but it is less accurate.
utf8_unicode_ci: It is used for better accuracy but little slow as compare to utf8_general_ci.

You can also use for specific languages like utf8_swedish_ci.


Question: Give an example of Transaction with commit and rollback?
try {
    // First of all, let's begin a transaction
    $db->beginTransaction();

    // A set of queries; if one fails, an exception should be thrown which we are handling at bottom
    $db->query('1 query exe');
    $db->query('2 query exe');
    $db->query('3 query exe');
    
    $db->commit();
} catch (Exception $e) {
    // An exception has been thrown by try
    //This function have all the things which you want to rollback.

    $db->rollback();
}


Question: How to use "MySQL in clause" for "string search" and "number search"?
When we are searching with number: We need not to add single quote
$sql=mysql_query('SELECT * FROM `users` WHERE id IN ( 1, 2, 34 )');
while($data = mysql_fetch_array($sql)){
    //write here your code
}
When we are searching with string:Its compulsory to add single OR double quote.
$sql=mysql_query("SELECT * FROM `users` WHERE email in('myemail@gmail.com','anotheremail@gmail.com','testemail@gmail.com')");
while($data = mysql_fetch_array($sql)){
    //write here your code
}


Question: How to get the closed 10 locations between with lat long?
You can try below MySQL as its working for me:
$sql='SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) 
* cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin(radians(lat)) ) ) AS distance 
FROM city HAVING distance < 25 ORDER BY distance asc limit 0,10';

while($data = mysql_fetch_array($sql)){
    //write here your code
}



Question: How to use update query based on SELECT Query?
You have to use the join for this, See below format:
update tab1
left join table2 tab2 on
    tab1.name = tab2.name
set
    update_field = if(start_dates > end_dats, 'valid', 'Not-valie')



Queston: How to optimize table?
OPTIMIZE TABLE `users` 



Question: How to repair table?
you can use any of below:
REPAIR TABLE users
REPAIR TABLE users QUICK
REPAIR TABLE users EXTENDED