background preloader

URL Rewriting for Beginners

URL Rewriting for Beginners
A beginner's guide to URL rewriting, with plenty of examples. Introduction URL rewriting can be one of the best and quickest ways to improve the usability and search friendliness of your site. There are several other guides on the web already, that may suit your needs better than this one. Apache URL Rewriting Guide - The best guide around Before reading on, you may find it helpful to have the mod_rewrite cheat sheet and/or the regular expressions cheat sheet handy. What is "URL Rewriting"? Most dynamic sites include variables in their URLs that tell the site what information to show the user. The problems with this kind of URL structure are that the URL is not at all memorable. Clearly a much cleaner and shorter URL. Now we're getting somewhere. Unfortunately, the last URL cannot be easily understood by a server without some work on our part. Platforms and Tools . Flags Conditions

rewrite Available Languages: en | fr Summary This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule, to provide a really flexible and powerful URL manipulation mechanism. The URL manipulations can depend on various tests, of server variables, environment variables, HTTP headers, or time stamps. This module operates on the full URLs (including the path-info part) both in per-server context (httpd.conf) and per-directory context (.htaccess) and can generate query-string parts on result. Further details, discussion, and examples, are provided in the detailed mod_rewrite documentation. Quoting Special Characters Environment Variables This module keeps track of two additional (non-standard) CGI/SSI environment variables named SCRIPT_URL and SCRIPT_URI. Example Rewriting in Virtual Hosts RewriteEngine On RewriteOptions Inherit

A T-SQL Regular Expression Library for SQL Server 2005. Free source code and programming help Introduction With the advent of CLR integration into SQL Server 2005, it has become incredibly easy to extend the power of the T-SQL programming language. Two of the areas that can be improved upon by way of CLR integration are string matching and string manipulation. Background T-SQL has a handful of basic string matching functions (e.g. SQL Server 2005 now allows you to create user defined functions (among other things) using your .NET language of choice. Using the Code General Approach My objective here is to wrap some of the more commonly used static methods of the RegEx class in the .NET Framework into something useable in a T-SQL environment. Interface All four of the functions listed in this article share the same first two parameters: @Input NVARCHAR(MAX) This is the string to be analyzed. @Pattern NVARCHAR(MAX) This is the regular expression which will be executed against the @Input parameter. In addition, all four functions share the same last parameter. @IgnoreCase BIT Functions Name

Apache mod_rewrite mod_rewrite provides a way to modify incoming URL requests, dynamically, based on regular expression rules. This allows you to map arbitrary URLs onto your internal URL structure in any way you like. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule to provide a really flexible and powerful URL manipulation mechanism. Rewrite rules can operate on the full URLs, including the path-info and query string portions, and may be used in per-server context (httpd.conf), per-virtualhost context (<VirtualHost> blocks), or per-directory context (.htaccess files and <Directory> blocks). Since mod_rewrite is so powerful, it can indeed be rather complex. Rejex lets you craft regular expressions on-the-fly Rejex is a very handy little site for building and testing regular expressions on the fly. It's composed of four simple text boxes and a very informative cheat sheet (not shown above, but after the jump). You feed your text into the "Test String" box (the middle one), and then your expression into the top box, and immediately see the matches in the bottom box. Here I am searching for instances of the letter "o" which are either at the beginning or the end of a word, so I got a match for "over" but not for "fox". Half the tool's value lies with the informative cheat sheet, showing you exactly what each regex character does. The regex cheat sheet:

301 Redirect Htaccess Examples You are here: home 301 redirects When updating any website with a new page structure, re-naming page URL's or changing the path of web pages by adding folders or altering folder names, many webmasters forget or simply don’t appreciate the SEO benefits of using Mod Rewrite or simple "301 redirects" to redirect old pages to new. A different, but equally popular application for 301 redirects is to redirect all visitors to a certain website to another domain, either on a page by page basis or to redirect all pages on an old unused domain to a single page on a new domain - the homepage for example. 301's are often referred to as "Redirect Permanent", so as the name implies they are used to permanently redirect one web page to another - and are recommended by Google as the best method of implementing web page redirects. HTACCESS File SEO Benefits of 301 Redirects Usability Benefits Mod Rewrite Procedure & 301 Redirect Examples Mod Rewrite rules are applied using an HTACCESS file. Wildcard Redirects

An Introduction to Regular Expressions. Free source code and programming articles This document describes the theory behind regular expressions (RE) as well as their practical usage. Table of Content What are Regular Expressions? Regular expressions are a way to search for substrings ("matches") in strings. This is done by searching with "patterns" through the string. Example You probably know the '*' and '?' When using a pattern like "text?. textf.txt text1.asp text9.html But it will not find files like text.txt text.asp text.html This is exactly the way REs work. Why would you use Regular Expressions Example usages could be: Remove all occurences of a specific tag from an html file Check whether an e-mail address is well-formed Standard Regular Expression Operations Basically you can do the following operations on a string with REs: Test for a pattern I.e. search through a string and check whether a pattern matches a substring, returning true or false. Where to use Regular Expressions Following are some other languages for which RE libraries exist: Search a string for a pattern

MOD_REWRITE for Dummies This article is not a complete guide to Apache's mod_rewrite neither to .htaccess. Its purpose is to help you - the webmaster - to create "mod_rewriten" versions of your dynamic webpages even if you have limited technical knowledge. I won't show you all the tips-and-tricks - my aim is to bring all the complexity of the Apache's documentation to 1-2 pages of human language - easy and fast. What is mod_rewrite? Mod_rewrite is Apache extension which allows you to "rewrite" the URLs of your web pages. www.mywebsite.com/index.php? This can easy be 'translated' into www.mywebsite.com/par1/par2/par3 Why mod_rewrite? Search engine optimization - there are a lot of debates on this topic, but it is still true that the static-looking links rank better than the dynamic ones. How to use it? Mod_rewrite is really powerful if you are familiar with the regular expressions which it uses.But learning the whole pattern syntax can be quite complicated, especially for the non-technical user. Lets start:

Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns Stupid htaccess Tricks Welcome to Perishable Press! This article, Stupid htaccess Tricks, covers just about every htaccess “trick” in the book, and is easily the site’s most popular offering. In addition to this htaccess article, you may also want to explore the rapidly expanding htaccess tag archive. Along with all things htaccess, Perishable Press also focuses on (X)HTML, CSS, PHP, JavaScript, security, and just about every other aspect of web design, blogging, and online success. If these topics are of interest to you, I encourage you to subscribe to Perishable Press for a periodic dose of online enlightenment ;) General Information [ ^ ] .htaccess Definition 1 ^ Apache server software provides distributed (i.e., directory-level) configuration via Hypertext Access files. Commenting .htaccess Code ^ Comments are essential to maintaining control over any involved portion of code. Important Notes for .htaccess Noobs ^ As a configuration file, .htaccess is very powerful. Performance Issues ^ [S=x] [E=variable:value]

Stupid htaccess Tricks Welcome to Perishable Press! This article, Stupid htaccess Tricks, covers just about every htaccess “trick” in the book, and is easily the site’s most popular offering. In addition to this htaccess article, you may also want to explore the rapidly expanding htaccess tag archive. Along with all things htaccess, Perishable Press also focuses on (X)HTML, CSS, PHP, JavaScript, security, and just about every other aspect of web design, blogging, and online success. If these topics are of interest to you, I encourage you to subscribe to Perishable Press for a periodic dose of online enlightenment ;) General Information [ ^ ] .htaccess Definition 1 ^ Apache server software provides distributed (i.e., directory-level) configuration via Hypertext Access files. Commenting .htaccess Code ^ Comments are essential to maintaining control over any involved portion of code. Important Notes for .htaccess Noobs ^ As a configuration file, .htaccess is very powerful. Performance Issues ^ [S=x] [E=variable:value]

Related: