htaccess/web.config url rewrite from asp to php

.HTACCESS:

<IfModule mod_rewrite.c>
RewriteEngine On

#REWRITE RULES
#———————

#RULE REMOVING .PHP
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond {REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

#RULE ASP CLASSIC LEGACY 301 REDIRECT TO PHP
RewriteCond %{QUERY_STRING} id=([_0-9a-z-]+)
RewriteRule Content\.asp$ %1 [r=301,L]

</IfModule>

 

WEB.CONFIG:

<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”removing .php” stopProcessing=”true”>
<match url=”^(.*)$” />
<conditions logicalGrouping=”MatchAll”>
<add input=”{REQUEST_FILENAME}” matchType=”IsFile” ignoreCase=”false” negate=”true” />
<add input=”{REQUEST_FILENAME}.php” matchType=”IsFile” ignoreCase=”false” />
</conditions>
<action type=”Rewrite” url=”{R:1}.php” />
</rule>
<rule name=”Asp classic legacy 301 redirect to php” stopProcessing=”true”>
<match url=”Content\.asp$” />
<conditions>
<add input=”{QUERY_STRING}” pattern=”id=([_0-9a-z-]+)” />
</conditions>
<action type=”Redirect” url=”{C:1}” redirectType=”Permanent” appendQueryString=”false”/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Uploadify Uploadifive support check

Check if the browser supports “multiple” attribute for input file element, this way you don’t have to worry about browser or its version. You are only checking the browser feature.

var inputFile=document.createElement(“input”);

if(typeof inputFile.multiple!=”undefined”) return “Supports Uploadifive!”;
else return “Supports Uploadify!”;

 

Escape strings issue universal fix

Escape strings #onebigissue in programming, My solution works for all.

Say I have a textarea field “notes”


To encode all the special characters for passing the data, you’ll need to use “encodeURIComponent()”.
The encodeURIComponent doesn’t encode ~!*()’
To encode the remaining i have a function to replace single quotes in an encoded string.

function encodeURIComponentReplace(encodeString){
  //encodeURIComponent() will not encode: ~!*()' - use this function to do the job	
  var intIndexOfMatch = encodeString.indexOf( "'" );
  while (intIndexOfMatch != -1){
    encodeString = encodeString.replace( "'", "%27" )
    intIndexOfMatch = encodeString.indexOf( "'" );
  }
  return encodeString;
}

If you send the parameters in GET method to PHP backend,
you’ll receive parameter values with added slashes.
You should strip slashes and convert the htmlentities before database insert/update.

PHP:
$notes=htmlspecialchars(stripslashes($notes),ENT_QUOTES);

If you send the parameters in POST method you do not have to do the above step.

Retrieving the data from the database using PHP.

If you are simply echoing values from the database to front-end use the following PHP code:
$notes=rawurldecode(htmlspecialchars_decode($notes,ENT_QUOTES));

If you are sending values in a json array do the following before encoding:
$notes=rawurldecode($notes);
then json_encode the output array.