Xem mẫu

the tag tells it to. This is how many people handle these sorts of cases. There`s one obvious problem, though. Let`s say you had many pages in the aboutus directory. You`d have to create pages like this one to replace each of them. The other, slightly less obvious problem, is that these tags mess with the Back button. Unless users are careful, they`ll go back to the redirect page, get redirected to the new page again, go back again, get redirected again, and on and on. To get back past a page that uses a tag to redirect users, you have to click the Back button twice in rapid succession. Using the Redirect directive, you can solve this problem much more elegantly. Here`s how it works: Redirect /aboutus http://www.example.com/about Any requests for URLs that begin with /aboutus will be redirected to the /about directory. Apache will also take everything after the path specified in the Redirect directive and append it to the target URL. So, a request for /aboutus/management.html will be redirected to http://www.example.com/about/ management.html. This makes the redirection completely transparent to the user. You can even specify whether the redirect is permanent or temporary like this: Redirect temp /aboutus http://www.example.com/about Redirect permanent /aboutus http://www.example.com/about Redirect seeother /aboutus http://www.example.com/about You can indicate that /aboutus is gone without redirecting the user like this: Redirect gone /aboutus That`s a more civilized thing to do than letting your users run into 404 errors. If you need to match something other than the beginning of the URL, you can use RedirectMatch, which uses regular expressions as the matching part of the URL. There`s no space here to discuss regular expressions, but I`ll give you one example of how RedirectMatch works. Let`s say you replace all of your . html files on your site with .php files so that you can use PHP includes for navigation. Here`s the rule: RedirectMatch (.*)\.html$ http://www.example.com$1.php Let me break that down. It basically says that any URL ending in .html should be redirected to the same URL on the server http://www.example.com except that the .html ending should be replaced with .php. First, let`s look at the URL to match, from end to beginning. It ends with $, which indicates that the string to be matched must be at the end of the URL. The \.html is the string to match. The \ is in there to indicate that the . should actually appear in the URL, and not be treated as a regular expression metacharacter. The (.*) says "match everything up to the .html." The .* matches everything, and the parentheses indicate that the regular expression should remember what was matched. In the target URL, the part of the URL that was matched is retrieved and plugged in. file:///G|/1/0672328860/ch19lev1sec3.html (4 von 4) [19.12.2006 13:50:11] Summary Throughout this book, I`ve talked about HTML, JavaScript, images, and other techniques that work regardless of whether your web pages live on a web server, on a CD-ROM, or in a work directory on your local hard drive. There`s more to web servers, though, than just serving up static web pages when users request them, and this lesson was just the tip of the iceberg when it comes to exploring the additional capabilities of web server software. I discussed some popular web application development platforms. You probably don`t need to know all of them, but if you do much web development, eventually you`ll wind up using one of them or another. I also talked about how you can take advantage of server features such as server-side includes, access control, and redirection features built into the server to make your life as a web developer easier. The key here is to take advantage of the features your web server offers to save yourself work and provide a better experience for your users. You should look into the web server that your pages will reside on for more ways to take advantage of it. file:///G|/1/0672328860/ch19lev1sec4.html [19.12.2006 13:50:11] Workshop This workshop contains some questions about HTML validation, as well as a quiz and exercises that will refresh your memory on what you`ve learned. Q&A Q How do I figure out which web server I use? A If you don`t know which web server your web pages reside on, you can ask the system administrator responsible for making sure it`s up and running; he`ll certainly know. Or you can use Netcraft`s site to figure out the server software and operating system for your site. Just go to http://uptime.netcraft.com/up/graph/. Enter the hostname of the computer where your pages are stored to get information about the software running on your server. Q Does using the web application platforms require me to be a programmer? A No more so than learning to use Dynamic HTML or JavaScript. There are some really simple things you can do to take advantage of these platforms, and at the same time you can write really complex applications as well, like the ones that power huge sites like Amazon.com and Yahoo!. Quiz 1. What`s the relationship between the web server and CGI programs? 2. What are the two standard languages associated with programming in Active Server Pages? 3. What are the two types of includes in the J2EE world? 4. In PHP, how do the require() and include() functions differ? file:///G|/1/0672328860/ch19lev1sec5.html (1 von 2) [19.12.2006 13:50:11] 5. When using server-side includes, how do virtual and file includes differ? Quiz Answers 1. CGI programs are standalone programs that are invoked by the web server. They produce data in a format that the web server understands how to send to the browser. 2. The two standard languages that can be used with ASP are VBScript and JavaScript. 3. In the J2EE world, there are compile-time includes and runtime includes. Code in compile-time includes can interact with code in the including file. Runtime includes must be independent. 4. If the file cannot be included when you use the require() function to include a file in PHP, the page fails to load. If include() is used, PHP proceeds with a warning. 5. When you use virtual includes with SSI, the file can exist anywhere under the document root. When you use file, the file must be in or below the current directory. Exercises 1. Find out which web server you use and figure out how to apply includes to your website. 2. If you have a web application environment available for your server, find a site that offers free sample programs and take a look at some. file:///G|/1/0672328860/ch19lev1sec5.html (2 von 2) [19.12.2006 13:50:11] Lesson 20. Understanding Server-Side Processing At this point, you`ve learned how to publish websites using HTML. This lesson takes things a step further and explains how to build dynamic websites using scripts on the server. Rather than trying to explain several of the platforms described in Lesson 19, "Taking Advantage of the Server," I`m focusing on PHP in this lesson. PHP is the most common scripting platform provided by web hosts, can be easily installed on your own computer, and is completely free. It`s also easy to get started with. Even if you wind up developing your applications using some other scripting language, you can apply the principles you`ll learn in this lesson to those languages. In this Lesson ● How PHP works ● How to set up a PHP development environment ● The basics of the PHP language ● How to process form input ● Using PHP includes file:///G|/1/0672328860/ch20.html [19.12.2006 13:50:12] ... - tailieumienphi.vn
nguon tai.lieu . vn