Jack is Here, asp.net findings

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries for the ‘html tutorial’ Category

How to use mod_rewrite to simplify URL Rewriting in Apache – A basic guide to the mod_rewrite module

Introduction

URL rewriting is the process of manipulating a URL or a link to send to a web server in a way that the link will be dynamically changed on the server to include additional parameters and information together with a server initiated realignment. The Web server performs all these manipulations on the fly, so that the browser of the loop on the change in the URL and the redirection is considered authenticated.

URL Rewriting can benefit your websites and web based applications by providing better security, better visibility or friendliness with Search Engines and helps in keeping the structure of the website more easy to maintain for future changes.

You can read about the theory and benefits of URL Rewriting from my Previous article, which can be accessed from here. In this article we will be taking a look at how we can implement URL Rewriting on an Apache based web server environment using the mod_rewrite module for Apache.

What is mod_rewrite?

Mod_rewrite is one of the most favored modules for the Apache web server and there are many web developers and administrators who will vote this module as the best thing to happen on Apache. This module has a lot of tricks up its sleeve so that it can be called the Swiss Army Knife of all Apache Modules. Apart from providing simple URL Rewriting functionality for an Apache based website, this module arms the website with better URL protection, better search engine visibility, protection against bandwidth thieves by stopping hot linking, hassle free restructuring possibilities and options to provide friendliest of URLs for the website users. This module due to its versatility and functionality can at times feel a bit daunting to master, but getting a through understanding of the basics can make you a master of the craft of URL Rewriting.

Lets Begin! – A look at all the stuff you need to have on your test environment to get mod-rewrite alive and kicking.

First of all, must be on your test machine is configured correctly for Apache Web server. mod_rewrite is usually installed with the Apache server, but if it is missing – this can be on a Linux machine, such as the case was not compiled mod_rewrite module installed along – you have to get it installed. Apache's mod_rewrite to use your box you must configure the module loaded by Apache's dynamic needs. In a shared server you have with your web hosting company to obtain the module installed and Apache from loading.

On your local machine you can find if the module is installed along with Apache by having a look at the modules directory of Apache. Check for a file named mod_rewrite.so and if it is there then the module can be made to load in to the Apache server dynamically. By default this module is not loaded when Apache starts and you need to tell Apache to enable this module for dynamic loading by making changes in the web servers configuration file, which is explained below.

How to Enable mod_rewrite on Apache?

You can make the mod_rewrite module load dynamically in to the Apache web server environment using the LoadModule Directive in the httpd.conf file. Load this file in a text editor and find a line similar to the one given below.

#LoadModule rewrite_module modules/mod_rewrite.so

Uncomment this line by removing the # and save the httpd.conf file. Restart your Apache server and if all went well mod_rewrite module will now be enabled on your web server.

Lets Rewrite our first URL using mod_rewrite

Ok, now the mod_rewrite module is enabled on your server. Lets have a look at how to make this module load itself and to make it work for us.

In order to load the module dynamically you have to add a single line to your .htaccess file. The .htaccess files are configuration files with Apache directives defined in them and they provide distributed directory level configuration for a website. Create a .htaccess file in your web servers test directory – or any other directory on which you want to make URL Rewriting active – and add the below given line to it.

RewriteEngine on

Now we have the rewrite engine turned on and Apache is ready to rewrite URLs for you. Lets look at a sample rewrite instruction for making a request to our server for first.html redirected to second.html at server level. Add the below given line to your .htaccess file along with the RewriteEngine directive that we have added before.

RewriteRule ^first.html$ second.html

I will explain what we have done here at the next section, but if all went well then any requests for first.html made on your server will be transferred to second.html. This is one of the simplest forms of URL Rewritting.

The point here to note that the redirection is completely hidden from the client, this is a classic and HTTP redirect are held differently. Client or browser content first.html second.html give the impression that we are fetching from. This website is awareness of the client, what is the URL you have been very powerful URL rewriting can be generated on the fly.

Basics of mod_rewrite module

Now we know that mod_rewrite can be enabled for an entire website or a specific directory by using .htaccess file and have done a basic rewrite directive in the previous example. Here I will explain what exactly have we done in the first sample rewrite.

Mod_rewrite module provides a set of configuration directive statements for URL Rewriting and the RewriteRule directive – that we saw in the previous sample – is the most important one. The mod_rewrite engine uses pattern-matching substitutions for making the translations and this means a good grasp of Regular Expressions can help you a lot.

Note: Regular Expressions are so vast that they will not fit in to the scope of this article. I will try to write another article on that topic someday.

1. The RewriteRule Directive

The general syntax of the RewriteRule is very straightforward. RewriteRule Pattern Substitution [Flags]

The Pattern part is the pattern which the rewrite engine will look for in the incoming URL to catch. So in our first sample ^first.html$ is the Pattern. The pattern is written as a regular expression.

The Substitution is the replacement or translation that is to be done on the caught pattern in the URL. In our sample second.html is the Substitution part.

Flags are optional and they make the rewrite engine to do certain other tasks apart from just doing the substitution on the URL string. The flags if present are defined with in square brackets and should be separated by commas.

Lets take a look at a more complex rewrite rule. Take a look at the following URL.

http://yourwebsite/articles.php?category=stamps&id=122

Now we will convert the above URL in to a search engine and user friendly URL like the one given below.

http://yourwebsite/articles/stamps/122

Create a page called articles.php with the following code:

$category = $_GET['category'];

$id = $_GET['id'];

echo “Category : ” . $category . ” “;

echo “ID : ” . $id;

This page simply prints the two GET variables passed to it on the webpage.

Open the .htaccess file and write in the below given Rule.

RewriteEngine on
RewriteRule ^articles/(w+)/([0-9]+)$ /articles.php?category=$1&id=$2


The pattern ^articles/(w+)/([0-9]+)$ can be bisected as:

^articles/ – checks if the request starts with ‘articles/’

(w+)/ – checks if this part is a single word followed by a forward slash. The parenthesis is used for extracting the parameter values, which we need for replacing in the actual query string, in the substituted URL. The pattern, which is placed in parenthesis will be stored in a special variable which can be back-referenced in the substitution part using variables like $1, $2 so on for each pair of parenthesis.

([0-9]+)$ – this checks for digits at the last part of the url.

Try requesting the articles.php file in your test server with the below given url.

http://yourwebsite/articles/coins/1222

The URL Rewrite rule you have written will kick in and you will be seeing the result as if the url requested where:

http://yourwebsite/articles.php?category=coins&id=1222

Now you can work on this sample to build more and more complex URL Rewritting rules. By using URL rewriting in the above example we have achieved a search engine and user friendly URL, which is also tamper proof against casual script kiddie injection sort of attacks.

What does the Flags parameter of RewriteRule directive do?

RewriteRule Flags offer us a way to control each of the mod_rewrite rule. These flags are defined separately in a single set of square brackets with commas, and there are about 15 flags to choose from. These flags range from those who are the way legislation is complicated and controls such as those specific HTTP headers sent back to the client when a match is found using the model.

Lets look at some of the basic flags.

  • [NC] flag (nocase) –. This makes mod_rewrite to treat the pattern in a case-insensitive manner.
  • [F] flag (forbidden) – This makes Apache send a forbidden HTTP response header – response 403 – back to the client.
  • [R] flag (redirect) – This flag makes mod_rewrite to use a formal HTTP redirect instead of the internal Apache redirect. You can use this flag to inform the client about the redirection and this flag sends a Moved Temporarily – Response 302 – by default, but this flag takes an extra parameter, which you can use to modify the response code. If you wish to send a response code of 301 – Moved Permanently – then this flag can be written as [R=301]
  • [G] flag (gone) – This flag makes Apache respond with a HTTP Response 410 – File Gone.
  • [L] flag (last) – This makes mod_rewrite to stop processing succeeding directives if the current directive is successful.
  • [N] flag (next) – This flag makes the rewrite engine to stop process and loop back to start of the rule list. A point to note is that the URL, which will be used for pattern matching, will be the rewritten one. This flag can create an endless loop and so extreme care should be given while using it.

There are other flags too but they are complex to explain with in the scope of this article so you can find more info on them by referring the mod_rewrite manual.

2. The RewriteCond Directive

This directive provides you with a range of specifications and conditions within the conditional examination of additional power. When combined with the RewriteRule will allow you to rewrite the conditions for success-based Web site with this statement. RewriteCond like if () statement in the programming language, but they can decide whether an alternative RewriteRule directives should be carried out or is not here. And so on to prevent the hot link and check whether the client meets certain criteria such as URL rewriting before, you can use this command to achieve.

The general syntax of the RewriteCond is:

RewriteCond string-to-test condition-pattern

The string-to-test part of the RewriteCond has access to a large set of Variables like the HTTP Header variables, Request Variables, Server Variables, Time variables etc so you can do a lot of complex conditional checking while writing directives. You can use any of these variables as a string to test by putting it in a %{string} format. Suppose you want to use the HTTP_REFERER variable then it can be used as %{HTTP_REFERER }.

The condition part can be a simple string or a very complex regular expression as your imagination is the only limit with this module.

Lets take a look at an example for conditional rewriting using RewriteCond directive:

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4(.*)MSIE
RewriteRule ^index.html$ /index.ie.html [L]

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/5(.*)Gecko
RewriteRule ^index.html$ /index.netscape.html [L]

RewriteRule ^index.html$ /index.other.html [L]

This example used as a test string with the RewriteCond directive HTTP_USER_AGENT. It does is that it uses the HTTP_USER_AGENT header variable to find access to the user's browser and matching the known values for the pre-set detector and serve different pages based on the results of the competition of visitors. The first RewriteCond checks to find a match HTTP_USER_AGENT^Mozilla/4(.*)MSIE pattern. This match will occur when a user visits the page using IE as browser. Then the RewriteRule given just under that statement will kick in and will rewrite the URL to server index.ie.html page to the IE visitor.

Similarly a checking is made for mozilla specific browsers in the second RewriteCond and the RewriteRule will do the substitution for index.netscape.html when a positive match is made on the ^Mozilla/5(.*)Gecko pattern. The third RewriteRule is there to catch other browsers. If both the first and second RewriteCond fails then the last RewriteRule will be considered. A point to note in the above example is the usage of the [L] flag with all the RewriteRule directives. This is used to avoid the cascading of applying the rules when a positive RewriteRule is applied.

Two flags which can be used to further control the way the RewriteCond directive behave are [NC] – case-insensitive – and [OR] – chaining of multiple RewriteCond directives with logical OR.

By using these two directives – RewriteRule and RewriteCond – you can implement a lot of powerfull URL Rewriting functionality on your website.

Other mod_rewrite Directives

  1. RewriteBase Directive – This directive can solve the problem of RewriteRule creating non-existent URLs due to difference in the physical file system structure on web server and the structure of website URLs. Setting this directive to the below given statement can solve this problem.

    RewriteBase /

  2. RewriteMap Directive – This directive is very powerful as it allows you to map unique values to a set of other replacement values from a table and to use it in the substitution to generate on the fly URLs. This can be especially useful for huge e-commerce or CMS kind of applications where you need to replace each section name or category name in the URL with a corresponding id taken from a database.
  3. RewriteLog Directive – This directive can be used to set the log file that the mod_rewrite engine will use to log all the actions taken during processing on client requests. The syntax is:

    RewriteLog /path/to/logfile

    This directive should be defined in the httpd.conf file as this directive is applied on a per-server basis.

  4. RewriteLogLevel Directive – This directive tells mod_rewrite module the amount of information on the internal processing done while rewriting URLs to be logged. This directive takes values from 0 to 9 where 0 means no logging and 9 means all the information is logged. A higher level of logging can make Apache run slow, so a level above 2 is desired only for debugging purposes. This directive can be applied using the below given syntax.br/>
    RewriteLogLevel levelnumber

Conclusion

In this article we have taken only a brief look at the power of the mod_rewrite module. It is only a scratch on the surface but I hope it is enough to get you started on using this module on your web server environment.

How To Have Your Own Content Rich Web Site

It has a lot of its content and how Web has recognized the importance of the site. On this score, visit the traffic in order, Web search engine ranking helps to increase the amount of the site. However, you can type a Web site if you like what you do not need to pay a fortune not designers?

If you want your content is rich, you may consider using open source content management systems in the world. One thought is that Joomla and, more is free.

If you want to consider using Joomla, then you should first take into consideration some time to read and watch all kinds of Joomla tutorials available on the network. Although there are a reasonable learning curve, once you have mastered the basics is quite straight forward.

The great thing about Joomla is that you put on

So let’s take a look at the benefits of using this type of software:

  • Content: It goes without saying, a content rich site requires a lot of content and if you are like me, you know how long this takes to produce, but with Joomla you can allocate other users to edit your content. That is not to say that you will suddenly see that you have content that you haven’t approved of. You can set up users with different access levels for example; you may simply want a colleague to submit news articles for you and this can be done by setting up a user to be able to login and create content but you will still have the ability to approve of the content before it is published.
  • Design: With the content taken care of the next question you may have is “how am I going to make my site look professional?” Another great feature of Joomla is the fact that you can obtain templates that you simply upload and Joomla will display almost immediately. This takes the headache out of having to worry about learning how to use Photoshop, HTML or Cascading Style Sheets etc. There are many sites on the net who offer Joomla templates. Some you will have to pay for and some you will find complicated, but with a little research and time you will find a design that fits your site.
  • Functionality: When you have got your content and design sorted, you can start to look at how you can add extra functionality to your site such as you may decide that you want to add a shopping system or a blog or a Social Community area and this is where you will find an industry of programmers who can offer you virtually any functionality that you can think of and many of these add-ons are free

So you can really see that Joomla is a flexible system that allows you to grow your site as you become more experienced and with little time spent reading and watching the video tutorials and manuals available that will never wonder why they need help by professionals.

How to Get Massive Myspace Traffic – Part 3

(This article has been transcribed from a video on how to get MySpace traffic – you can follow along and use it to get traffic for your website).

We’re now going to go and customize my My Space page. Remember we’ve not added really anything very much at all at the moment, so let’s just work down. On this left-hand side we’re just going to go down here. I’m going to show you what you’ll need to do there.

So let’s go and edit profile. Now what you’ll get here when you first come in is a series of blank boxes, all different fields, About Me, I’d like to meet, Your interests, Music, etc. These are all blank.

As it is doing now, I have put examples of some of the text.

Now if you overdo it with adverts and links etc, then your account will get closed. As I said, I’m going to close this account anyway but I’m just doing this to show you what you could do, but you need to balance this out.

On me, just put your life story, basically, your life story or any other thing or things is to have these things, I have in the past. Remember that 4 hours. You must have a sincere nature of the. You have some aspect of the story. You must include a sense of humor, you have to information, provide you with useful.

So you just put text in here. “This is my story” or whatever it is in there. You can then move down to the next page and click “Preview here” if you want to preview it, and just work your way down.

As you can see here, you will be able to share links, so if you put a link in a particular section that you just use and share the code. You can obtain this code, by the way, if you are not sure that this just go to www.Google.com and enter

So let’s just say we’ve done that. We’ve gone through. We click on ‘Save all changes,’ and then what happens is this is what your profile then appears like. So this is my live profile, the public facing profile. So you can see we’re starting to add a little bit more.

We’ve added this About Me thing. We’ve added a link here, if you hop over that it’ll take you to the website of your choice if you want to get people more information, and a link here.

For additional information, remember that beneath the surface appeared interested in this. Link to us once again, people say we can send people to

I mean you’ve got to be careful with it. You can’t be a total traffic funnel commercial marketing nonsense. You’ve got to balance it out with the personal stuff and the real stuff, but you can use My Space to get a lot of traffic.

Now this list thing, this is just to show you another illustration of how you can actually use My Space. You can get a bit of code from your autoresponder, which I’ve gone through in another video, where you can actually place this code into your My Space and actually start building a list.

Now I’ve put there ‘Join my list.’ If you just say that you’re not going to get anybody joining your list. You’ve got to be helpful, as I’ve said. So if you have a bit of a story and say, “Look, I started out life. This is what I was doing.” Let’s just say you’re selling information on how to play better golf.

You could say, “Look, I played really bad golf and I read this book and now I’m a really good golfer. If you want me to tell you my full story, I’ll give you some free golf tips and information. Fill in the details here and I’ll give you a free ebook on golf.”

That is going to work really well because you’ve been helpful, you’ve been honest, it’s a human story, and it enables you to build a list using My Space, but it’s all about balance. You can’t totally overdo it.

So the first stage is kind of personalizing your profile and starting to get some traffic coming through.

Let’s just go back to the main page. We’ve edited our profile, our interests, and our personality. Let’s now move on to the next section.

We’ll go now onto Add Edit Photos. Just click on here. You can go in here and you can add a photo of your actual main profile, but you can also add many photos to your profile. So let’s just go and do that.

I’m just going to go and browse now. I’m going to go and upload some photos. So I’ve now updated some photos. You can keep uploading as many as you want here. I’ve just uploaded one that I’m going to use from my main profile.

This is one of my products, www.11DaysToListProfits.com, if you want to find out how to build a super powerful list. Get yourself off to that site, www.11DaysToListProfits.com, and this is my dog, who is not for sale and is not a product and will pretty much not teach you anything.

So those are some pictures. What you can now do is set one of these as a default image, and I’m going to choose this one, so that’s now going to be my default image for my profile. It’s going to appear on the top left of my particular profile.

As I can say, you can add a lot more photos down here. You can add captions to them and so on. The main point I’m trying to get across here is do add photos. All this is going to help personalize your My Space page, make you more unique, help people to get to know you better, etc.

Even now, what can be done, this is pretty common, very popular, is to add a slideshow to your profile. What is a slide show, as its name suggests, put something like this on your profile, leaving only a series of images, this is you get to know people very quickly can be placed to allow many people , in life you have to rotate pictures from the right, did different things on the page.

So let us just for this walk. We say

So you just grab the code here, highlight it, copy, and then you go back to your profile. Remember from the profile page it said you could post the HTML code anywhere. Go back in here, edit profile. So let’s just stick it in here. Let’s just say we’ll have it after the “paste” so we paste the code in, save all changes, and now we’ll go and look at what it actually looks like live online.

How To Create An HTML Image Background For Your Webpage

The easiest way to an HTML image background for your web pages with the help of everyday images, Photoshop's Slice tool, a table and repeating background image html code. The nice thing about this kind of design that you do not need, CSS, and extends it with the length of your website.

High Level Process

  • Find and fix images to use for header, content holder and footer
  • Open a new document in Photoshop the width of your web site.
  • Drag the images onto the template and position them so that the finished template resembles a web page (header at top, content area in middle surrounded by a border and footer at bottom)
  • Add a background color if desired
  • Slice the template into 3 sections
  • Save each section as a gif image and upload as usual
  • Build a 3-row table in the body section of your HTML document to hold each of the 3 gif images. Top row holds top gif image, middle row holds middle gif image and bottom row holds bottom gif image
  • Use repeating HTML code in the middle row so that the HTML image background expands vertically with the length of the page

Finding the Images

If you do not have images that are suitable for this purpose, search photo websites like IStockPhoto.

For the header and footer images, there are several combinations that will work, but if you want to keep it simple, use the same image(s) along the top that you use along the bottom.

An image can be copied and pasted several times, to fit the entire width of your template. A picture of the formation of wood, for example, can serve as a headline across the top and can turn be used along the bottom.

For the content holder, there are also several options. You can simply use a colored rectangle and add a shadow to it or you can use something like a picture frame to get a more ornate looking content holder.

Creating The Template For Your HTML Image Background

The template that you create in Photoshop is fully functional on it’s own. All you have to do is add content to the middle section of the table.

NOTE: If you use a cascading stylesheet (CSS) on the same web page, it will interfere with the effectiveness of the template. In some cases your middle gif will repeat horizontally instead of vertically.

As an example, the width of 950 pixels to create the document in white (which is) 600 pixels and a height (the height of your important and tell a Web page is not wide, so choose something, anything for you can see the size of the Photoshop).

Before dragging your images onto the template, you may have to fiddle with them so that they match the width of your template. For example, if you choose an image of wood moulding that is only 250 pixels wide, you will need to duplicate the layer repeatedly and position them side by side to get a longer piece of moulding that is 950 pixels wide.

Sometimes, when you copy and paste this side of the layer, the seams will be visible. Using the Smudge Tool blend seams, and then select the layer mosaic layer, so that you can easily drag the location of templates and access to its complete image.

If you want to use this exact image along the bottom, duplicate the layer and move it to the bottom. If you want to flip it, choose Edit-Transform-Rotate.

After preparing the content holder image (the picture frame in the example above), drag it onto the template positioning it between the header and the footer and then use Edit-Transform-Scale to stretch it to size.

Add Header Text (Website Name…) and Footer Text (Copyright…).

If you want to select it, use the Custom Shape tool and small pictures to add interest to your template. The spiral shape is a favorite. Use Edit-Transform, and scale or rotate either easy to size and position.

Find a complementary color in your images by using the Eyedropper Tool then fill the white space on either side of the content holder using the Paint Bucket Tool.

Use Slice Tool to Divide Template into 3 Images

Cut into three smaller image file level. Grab from the Tools panel Photoshop slice tool. In the top toolbar, set the style for the "fixed size" in order to ensure an accurate ratio. The use of 950px X 600px, for example, enter the width and height are as follows:

  • Top slice equals 950px X 250px
  • Middle slice equals 950px X 100px
  • Bottom slice equals 950px X 250px

CAUTION: Make sure that your top and bottom slices are large enough to completely contain the header and footer respectively.

Now you have a document sliced horizontally into 3 smaller pictures. The next step is to "Save for Web

Create a table in the body section of your HTML document to hold the background image url for each gif and your content.

  • The first row in your table contains the top gif
  • The middle row contains your middle gif, the repeating HTML code and the content
  • The last row in your table contains the bottom gif

These 3 gif images when displayed on a page will result in a one-of-a-kind, professional looking HTML image background, perfect for a simple web page or sales letter. The possibilities are only limited by your creativity.

How To Create A Web Page Shadow Using Photoshop Slice Tool and HTML Coding

For an easy-to-implement web page effect, add a Web Page Shadow all the way around your webpages using the Photoshop Slice Tool and HTML coding. Doing so not only adds visual interest but also gives your website a professional look. Read these step by step instructions or watch a video tutorial and follow along with a PDF supplement.

High Level Process:

  • Create 2 blank documents in Photoshop, one smaller than the other
  • On the smaller one, add a Photoshop drop shadow all the way around image
  • Drag the smaller document on top of the larger one to create one flattened image
  • Use the Photoshop Slice Tool to slice the image into 3 smaller images and upload as 3 separate gifs
  • Create a table in your HTML document within the body to hold gifs and content

Step By Step:

  • Create the larger of two documents in Photoshop (or another image editor). Width is the same as your website template (ex. 950 pixels). Height does not matter but should be big enough to easily use Photoshop Slice Tool (ex. 250 pixels). Color should be the same as your website body.
  • Create the smaller of two documents in Photoshop. Width should be smaller than the larger document (ex. 800 pixels). Height should be smaller than the larger document (ex. 100 pixels). Color should be the same as your content area.
  • Add a Photoshop Drop Shadow to the smaller document.
    • In the Layers Palette, double click on the word “Background” and change it to any other name. This will free up functionality and allow you to easily add a drop shadow.
    • Open the Layers Style dialog box, click on “Drop Shadow” and set the variables as follows:
      • Opacity 75%
      • Angle -90 degrees
      • Distance 0 px
      • Spread 35%
      • Size 35 px
      • Color #7B7979 (gray shadow)
  • Drag the smaller document on top of the larger document to create one image. Using the examples above, this image will be 950 pixels wide by 250 pixels high with the smaller, shadowed image embedded on top of it.
  • Slice the document into 3 smaller images horizontally.
    • Grab the Photoshop Slice Tool from the Tool Palette. In the top toolbar, set the Style to “Fixed Size” to ensure exact proportions. Using the 950px X 250px example, input width and height as follows:
      • Top slice equals 950px X 100px
      • Middle slice equals 950px X 50px
      • Bottom slice equals 950px X 100px
  • <!–Tags: , , , , , , , , ,