Diwakar's Blog

http://diwakarko.blogspot.com (दिवाकरको ब्लग)

Apache Authentication in htaccess

No comments

Require password for 1 file only

<files login.php>
Order deny,allow
Deny from all
AuthName "htaccess password prompt"
AuthType Basic
AuthUserFile /web/askapache.com/.htpasswd
Require valid-user
</Files>

Protect multiple files:

<FilesMatch "^(exec|env|doit|phpinfo|w).*$">
Order deny,allow
Deny from all
AuthName "htaccess password prompt"
AuthUserFile /.htpasswd
AuthType basic
Require valid-user
</FilesMatch>

Using the Apache Allow Directive in htaccess

network/netmask pair

Order deny,allow
Deny from all
Allow from 10.1.0.0/255.255.0.0

IP address

Order deny,allow
Deny from all
Allow from 10.1.2.3

More than 1 IP address

Order deny,allow
Deny from all
Allow from 192.168.1.104 192.168.1.205

Partial IP addresses, first 1 to 3 bytes of IP, for subnet restriction

Order deny,allow
Deny from all
Allow from 10.1
Allow from 10 172.20 192.168.2

network/nnn CIDR specification

Order deny,allow
Deny from all
Allow from 10.1.0.0/16

IPv6 addresses and subnets

Order deny,allow
Deny from all
Allow from 2001:db8::a00:20ff:fea7:ccea
Allow from 2001:db8::a00:20ff:fea7:ccea/10

Deny subdomains

Order Allow,Deny
Allow from apache.org
Deny from wireshark.apache.org

Allow from IP without password prompt, and also allow from any address with password prompt

Order deny,allow
Deny from all
AuthName "htaccess password prompt"
AuthUserFile /web/askapache.com/.htpasswd
AuthType Basic
Require valid-user
Allow from 172.17.10.1
Satisfy Any

Skeleton .htaccess file to start with

I use this when I start a new site, and uncomment or delete parts of the file depending on the sites needs
Ultimate htaccess file sample
#
#            DEFAULT SETTINGS
#
Options +ExecCGI -Indexes
DirectoryIndex index.php index.html index.htm
 
ErrorDocument 400 /cgi-bin/error.php
ErrorDocument 401 /cgi-bin/error.php
ErrorDocument 403 /cgi-bin/forbidden.cgi
ErrorDocument 404 /404.html
ErrorDocument 405 /cgi-bin/error.php
ErrorDocument 406 /cgi-bin/error.php
ErrorDocument 409 /cgi-bin/error.php
ErrorDocument 413 /cgi-bin/error.php
ErrorDocument 414 /cgi-bin/error.php
ErrorDocument 500 /cgi-bin/error.php
ErrorDocument 501 /cgi-bin/error.php
 
### DEFAULTS
ServerSignature Off
 
AddType video/x-flv .flv
AddType application/x-shockwave-flash .swf
AddType image/x-icon .ico
 
AddDefaultCharset UTF-8
AddLanguage en-US .html .htm .txt .xml .php
 
SetEnv TZ America/Indianapolis
SetEnv SERVER_ADMIN webmaster@askapache.com
 
### PHPINI-CGI
#AddHandler php-cgi .php
#Action php-cgi /cgi-bin/php5.cgi
 
### FAST-CGI
#AddHandler fastcgi-script .fcg .fcgi .fpl
#AddHandler php5-fastcgi .php
#Action php5-fastcgi /cgi-bin/fastcgi.fcgi
 
#
#           HEADERS and CACHING
#
# 1 YEAR
<FilesMatch ".(flv|ico|pdf)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
 
# 1 WEEK
<FilesMatch ".(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
 
# 3 HOUR
<FilesMatch ".(txt|xml|js|css)$">
Header set Cache-Control "max-age=10800"
</FilesMatch>
 
# 1 MIN
<FilesMatch ".(html|htm|php)$">
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
Header set P3P "policyref="/w3c/p3p.xml", CP="NOI DSP COR NID CUR ADM DEV OUR BUS""
Header set imagetoolbar "no"
</FilesMatch>
 
#
#          REWRITES AND REDIRECTS
#
### SEO REDIRECTS
#Redirect 301 /ssl-ns.html /2006/htaccess/apache-ssl-in-htaccess-examples.html
#Redirect 301 /ht.tml
#Redirect 301 /index.html /
#RedirectMatch 301 /2006/htaccess-forum/(.*) /2006/htaccess/$1
#RedirectMatch 301 /(.*)rfc2616(.*) http://rfc.askapache.com/rfc2616/rfc2616.html
#RedirectMatch 301 /phpmanual(.*) /manual/en/$1
 
### REWRITES
RewriteEngine On
RewriteBase /
 
### WORDPRESS
#<ifModule mod_rewrite.c>
#RewriteEngine On
#RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [L]
#</ifModule>
 
### REQUIRE WWW
#RewriteCond %{HTTP_HOST} !^www.askapache.com$ [NC]
#RewriteRule ^(.*)$ /$1 [R=301,L]
 
### STOP LOOP CODE
#RewriteCond %{ENV:REDIRECT_STATUS} 200
#RewriteRule ^.*$ - [L]
 
### REDIRECT BLOG FEED TO FEEDBURNER
#RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator|Recent) [NC]
#RewriteRule ^feed/?.*$ http://feeds.feedburner.com/apache/htaccess [L,R=302]
 
### BLOCK WGET
#RewriteCond %{HTTP_USER_AGENT} ^Wget.* [NC]
#RewriteRule .* /cgi-bin/forbidden.cgi [L]
 
#
#           AUTHENTICATION
#
### BASIC PASSWORD PROTECTION
#AuthName "Prompt"
#AuthUserFile /web/askapache.com/.htpasswd
#AuthType basic
#Require valid-user
 
### UNDER CONSTRUCTION PROTECTION
#AuthName "Under Development"
#AuthUserFile /web/askapache.com/.htpasswd
#AuthType basic
#Require valid-user
#Order Deny,Allow
#Deny from all
#Allow from 23.23.23.1 w3.org googlebot.com google.com google-analytics.com
#Satisfy Any

No comments :

Post a Comment

Auto Load and Refresh Div Using jQuery/Ajax & PHP/MySQL

1 comment
Have you seen this Twitter Search and Facebook shows most recent tweets/posts count from the database every 10 seconds on top of the page. I had developed like this with jQuery and Ajax. It's simple just 5 lines of code

Index.php
 



load.php



1 comment :

Post a Comment

Deploying an ASP.NET Web Application to a Windows Azure Web Site

No comments
Source: http://www.windowsazure.com/en-us/develop/net/tutorials/get-started/

This tutorial shows how to deploy an ASP.NET web application to a Windows Azure Web Site by using the Publish Web wizard in Visual Studio 2012 or Visual Studio 2012 for Web Express. If you prefer, you can follow the tutorial steps by using Visual Studio 2010 or Visual Web Developer Express 2010.
You can open a Windows Azure account for free, and if you don't already have Visual Studio 2012, the SDK automatically installs Visual Studio 2012 for Web Express. So you can start developing for Windows Azure entirely for free.
This tutorial assumes that you have no prior experience using Windows Azure. On completing this tutorial, you'll have a simple web application up and running in the cloud.
You'll learn:
  • How to enable your machine for Windows Azure development by installing the Windows Azure SDK.
  • How to create a Visual Studio ASP.NET MVC 4 project and publish it to a Windows Azure Web Site.
The following illustration shows the completed application:
Web site example
Note To complete this tutorial, you need a Windows Azure account that has the Windows Azure Web Sites feature enabled. If you don't have an account, you can create a free trial account in just a couple of minutes. For details, see Windows Azure Free Trial.

Tutorial segments

  1. Set up the development environment
  2. Create a web site in Windows Azure
  3. Create an ASP.NET MVC 4 application
  4. Deploy the application to Windows Azure
  5. Next steps

Set up the development environment

To start, set up your development environment by installing the Windows Azure SDK for the .NET Framework.
  1. To install the Windows Azure SDK for .NET, click the link that corresponds to the version of Visual Studio you are using. If you don't have Visual Studio installed yet, use the Visual Studio 2012 link.
    Windows Azure SDK for Visual Studio 2012
    Windows Azure SDK for Visual Studio 2010
  2. When you are prompted to run or save the installation executable, click Run.
  3. In the Web Platform Installer window, click Install and proceed with the installation.
    Web Platform Installer - Windows Azure SDK for .NET
  4. If you are using Visual Studio 2010 or Visual Web Developer 2010 Express, install MVC 4.
When the installation is complete, you have everything necessary to start developing.

Create a web site

The next step is to create the Windows Azure web site.
  1. In the Windows Azure Management Portal, click Web Sites, and then click New.
    New web site
  2. Click Quick Create.
    Quick create
  3. In the Create Web Site step of the wizard, enter a string in the URL box to use as the unique URL for your application.
    The complete URL will consist of what you enter here plus the suffix that you see next to the text box. The illustration shows example1, but if someone has already taken that string for a URL, you need to enter a different value.
  4. In the Region drop-down list, choose the region that is closest to you.
    This setting specifies which data center your web site will run in.
  5. Click the Create Web Site arrow.
    Create a new web site
    The Management Portal returns to the Web Sites page, and the Status column shows that the site is being created. After a while (typically less than a minute), the Status column shows that the site was successfully created. In the navigation bar at the left, the number of sites you have in your account appears next to the Web Sites icon.
    Web Sites page of Management Portal, web site created

Create an ASP.NET MVC 4 application

You have created a Windows Azure Web Site, but there is no content in it yet. Your next step is to create the Visual Studio web application project that you'll publish to Windows Azure.

Create the project

  1. Start Visual Studio 2012 or Visual Studio 2012 for Web Express.
  2. From the File menu, click New, and then click Project.
    New Project in File menu
  3. In the New Project dialog box, expand C# and select Web under Installed Templates, and then select ASP.NET MVC 4 Web Application.
  4. Ensure that .NET Framework 4.5 is selected as the target framework.
  5. Name the application MyExample and click OK.
    New Project dialog box
  6. In the New ASP.NET MVC 4 Project dialog box, select the Internet Application template and click OK.
    New ASP.NET MVC 4 Project dialog box

Run the application locally

  1. Press CTRL+F5 to run the application. The application home page appears in the default browser.
    Web site running locally
This is all you need to do to create a simple application that you'll deploy to Windows Azure.

Deploy the application to Windows Azure

  1. In Visual Studio, right-click the project in Solution Explorer and select Publish from the context menu.
    Publish in project context menu
    The Publish Web wizard opens.
  2. In the Profile tab of the Publish Web wizard, click Import.
    Import publish settings The Import Publish Profile dialog box appears.
  3. If you have not previously added your Windows Azure subscription in Visual Studio, perform the following steps. In these steps you add your subscription so that the drop-down list under Import from a Windows Azure web site will include your web site.
    a. In the Import Publish Profile dialog box, click Import from a Windows Azure web site, and then click Add Windows Azure subscription.
    add Windows Azure subscription
    b. In the Import Windows Azure Subscriptions dialog box, click Download subscription file.
    download subscription file
    c. In your browser window, save the .publishsettings file.
    download .publishsettings file
    Security Note The .publishsettings file contains your credentials (unencoded) that are used to administer your Windows Azure subscriptions and services. The security best practice for this file is to store it temporarily outside your source directories (for example in the Libraries\Documents folder), and then delete it once the import has completed. A malicious user who gains access to the .publishsettings file can edit, create, and delete your Windows Azure services.
    d. In the Import Windows Azure Subscriptions dialog box, click Browse and navigate to the .publishsettings file.
    download sub
    e. Click Import.
    import
  4. In the Import Publish Profile dialog box, select Import from a Windows Azure web site, select your web site from the drop-down list, and then click OK.
    Import Publish Profile
  5. In the Connection tab, click Validate Connection to make sure that the settings are correct.
    Validate connection
  6. When the connection has been validated, a green check mark is shown next to the Validate Connection button. Click Next.
    Successfully validated connection
  7. In the Settings tab, uncheck Use this connection string at runtime option, since this application is not using a database. You can accept the default settings for the remaining items on this page. You are deploying a Release build configuration and you don't need to delete files at the destination server, precompile the application, or exclude files in the App_Data folder.
    Click Next.
    Settings tab
  8. In the Preview tab, click Start Preview.
    StartPreview button in the Preview tab
    The tab displays a list of the files that will be copied to the server. Displaying the preview isn't required to publish the application but is a useful function to be aware of. In this case, you don't need to do anything with the list of files that is displayed.
    StartPreview file output
  9. Click Publish.
    Visual Studio begins the process of copying the files to the Windows Azure server.
  10. The Output window shows what deployment actions were taken and reports successful completion of the deployment.
    Output window reporting successful deployment
  11. Upon successful deployment, the default browser automatically opens to the URL of the deployed web site.
    The application you created is now running in the cloud.
    Web site running in Windows Azure

Next steps

In this tutorial, you've seen how to deploy a simple web application to a Windows Azure Web Site. Other resources are available to show you how to manage, scale, and troubleshoot the site, how to add database, authentication, and authorization functionality, and how to decide if your application should run in a Windows Azure Cloud Service instead of a Windows Azure Web Site.

How to manage a web site

When you're done with the site, you can delete it, and at times you might want to take it offline temporarily or change site settings. You can do some of these functions right from Server Explorer in Visual Studio.
Windows Azure Web Sites in Server Explorer
Web Site Configuration in Visual Studio
For more information, see Web Sites: Management Support within the Visual Studio Server Explorer in Announcing the release of Windows Azure SDK 2.0 for .NET on ScottGu's blog.
To delete your web site, you can use the Windows Azure Management Portal. The following screen shot shows Stop, Restart, and Delete buttons in the Dashboard tab of the management portal.
Management Portal Dashboard Tab
You can change site settings on the Configure tab. For more information, see How to Manage Web Sites.

How to scale a web site

When your site is public and it starts to get more traffic, response times might slow down. To remedy that, you can easily add server resources in the Scale tab of the management portal.
Management Portal Scale Tab
For more information, see How to Scale a Web Site. (Adding server resources to scale a web site is not free.)

How to troubleshoot a web site

If the site stops working correctly, you might want to look at trace or log output for help with troubleshooting. Visual Studio provides built-in tooling to make it easy to view Windows Azure logs as they are generated in real time.
Logs in Visual Studio
For more information, see Web Sites: Streaming Diagnostic Logs in Announcing the release of Windows Azure SDK 2.0 for .NET on ScottGu's blog. For information about web site monitoring functions that are available from the management portal, see How to Monitor Web Sites.

How to add database and authorization functionality

Most production web sites use a database and restrict some site functions to certain authorized users. For a tutorial that shows how to get started with database access, authentication, and authorization, see Deploy a Secure ASP.NET MVC app with Membership, OAuth, and SQL Database to a Windows Azure Web Site.

How to decide if your application should run in a Cloud Service

In some scenarios you might want to run your application in a Windows Azure Cloud Service instead of a Windows Azure Web Site. For more information, see Windows Azure Execution Models. For a tutorial series that shows how to create a multi-tier ASP.NET web application and deploy it to a Cloud Service, see .NET Multi-Tier Application Using Storage Tables, Queues, and Blobs.

No comments :

Post a Comment

PHP/MySQL Insert & Delete using jQuery/Ajax

No comments
Demo Download
 

Demo Download

No comments :

Post a Comment