Web Design and Development Forums

Simple Mod_Rewrite Examples

This is a discussion on "Simple Mod_Rewrite Examples" within the Apache and IIS section. This forum, and the thread "Simple Mod_Rewrite Examples are both part of the Hosting Related category.


Go Back   Webforumz.com > Hosting Related > Apache and IIS

Welcome to Webforumz.com.
Register Now Register now!

Closed Thread
 
LinkBack Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.
Old Feb 14th, 2008, 02:13   #1 (permalink)
Administrator
 
alexgeek's Avatar
 
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
Blog Entries: 9
Send a message via MSN to alexgeek
Exclamation Simple Mod_Rewrite Examples

A lot of people get confused with rewrites and don't have a clue how to write their own, hopefully this thread will help you you writing your own rewrites.
The Mod_Rewrite module of apache allows you to rewrite an boring URL to one which may benefit you or your users.

For rewrites to be enabled you must put the following at the top of your ".htaccess" file:
Code: Select all
Options +FollowSymLinks
RewriteEngine on

Below the above you can put your rewrites.
The following is basic rewrite that allows you to access www.example.com/feed.xml via the URL www.example.com/feed
Code: Select all
RewriteRule ^feed$ feed.xml [L]
The following is a more complex example. You may be familiar with the sytem where you pass an ID to a script by using a querystring, such as www.example.com/blog.php?id=1. We can rewrite this to look more attractive (and better for SEO) by using rewrites. Rewrites use regex to pass part of the URL accessed to the script and it's querystring.
The following allows us to access /blog.php?id=N via /blog/N-text-text-text
Code: Select all
RewriteRule ^blog/([0-9]+)-[a-zA-Z-]+$ blog.php?id=$1 [L]
Breakdown
^ - basically means "starts with".
blog/ - a literal.
([0-9]+): The numbers in square brackets with a plus means "any number" and the parentheses ( ) tell mod_rewrite that we want the match to be passed to the script as $1.
[a-zA-Z-]+ - This means match anything that is text from A to Z in upper or lower case, or a hyphen (-), repeated.

HTH

AlexGeek
TeamLeader
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.


alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flash examples collinsc Flash & Multimedia Forum 3 Oct 10th, 2007 15:24
Examples of your favorite navigation menus? mad samuel Website Planning Discussion 1 Aug 7th, 2007 17:48
Mod_rewrite ??? Blake121 PHP Forum 7 Jul 17th, 2007 16:33
Mod_Rewrite Request swiftmed PHP Forum 5 Jun 10th, 2006 06:05
Help with Mod_Rewrite swiftmed HTML Forum 3 Jun 7th, 2006 22:17



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 06:02.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59