admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
Derek Allard | afd99ac | 2008-01-19 19:59:14 +0000 | [diff] [blame] | 2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 3 | <head>
|
| 4 |
|
Derek Allard | 404e35d | 2007-08-07 01:00:45 +0000 | [diff] [blame] | 5 | <title>CodeIgniter User Guide : CodeIgniter URLs</title>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 6 |
|
| 7 | <style type='text/css' media='all'>@import url('../userguide.css');</style>
|
| 8 | <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
|
| 9 |
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 10 | <script type="text/javascript" src="../nav/nav.js"></script>
|
admin | 2296fc3 | 2006-09-27 21:07:02 +0000 | [diff] [blame] | 11 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 12 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
Derek Allard | b341237 | 2007-10-25 12:15:16 +0000 | [diff] [blame] | 13 | <script type="text/javascript" src="../nav/user_guide_menu.js"></script>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 14 |
|
| 15 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| 16 | <meta http-equiv='expires' content='-1' />
|
| 17 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 18 | <meta name='robots' content='all' />
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 19 | <meta name='author' content='ExpressionEngine Dev Team' />
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 20 | <meta name='description' content='CodeIgniter User Guide' />
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 21 |
|
| 22 | </head>
|
| 23 | <body>
|
| 24 |
|
| 25 | <!-- START NAVIGATION -->
|
| 26 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
|
| 27 | <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
|
| 28 | <div id="masthead">
|
| 29 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 30 | <tr>
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 31 | <td><h1>CodeIgniter User Guide Version 1.6.0</h1></td>
|
admin | c0d5d52 | 2006-10-30 19:40:35 +0000 | [diff] [blame] | 32 | <td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 33 | </tr>
|
| 34 | </table>
|
| 35 | </div>
|
| 36 | <!-- END NAVIGATION -->
|
| 37 |
|
| 38 |
|
| 39 | <!-- START BREADCRUMB -->
|
| 40 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 41 | <tr>
|
| 42 | <td id="breadcrumb">
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 43 | <a href="http://codeigniter.com/">CodeIgniter Home</a> ›
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 44 | <a href="../index.html">User Guide Home</a> ›
|
| 45 | URLS
|
| 46 | </td>
|
Derek Allard | bc03091 | 2007-06-24 18:25:29 +0000 | [diff] [blame] | 47 | <td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 48 | </tr>
|
| 49 | </table>
|
| 50 | <!-- END BREADCRUMB -->
|
| 51 |
|
| 52 | <br clear="all" />
|
| 53 |
|
| 54 |
|
| 55 | <!-- START CONTENT -->
|
| 56 | <div id="content">
|
| 57 |
|
| 58 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 59 | <h1>CodeIgniter URLs</h1>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 60 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 61 | <p>By default, URLs in CodeIgniter are designed to be search-engine and human friendly. Rather than using the standard "query string"
|
| 62 | approach to URLs that is synonymous with dynamic systems, CodeIgniter uses a <strong>segment-based</strong> approach:</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 63 |
|
| 64 | <code>www.your-site.com/<var>news</var>/<dfn>article</dfn>/<samp>my_article</samp></code>
|
| 65 |
|
| 66 | <p class="important"><strong>Note:</strong> Query string URLs can be optionally enabled, as described below.</p>
|
| 67 |
|
| 68 | <h2>URI Segments</h2>
|
| 69 |
|
| 70 | <p>The segments in the URL, in following with the Model-View-Controller approach, usually represent:</p>
|
| 71 |
|
| 72 | <code>www.your-site.com/<var>class</var>/<dfn>function</dfn>/<samp>ID</samp></code>
|
| 73 |
|
| 74 | <ol>
|
| 75 | <li>The first segment represents the controller <strong>class</strong> that should be invoked.</li>
|
| 76 | <li>The second segment represents the class <strong>function</strong>, or method, that should be called.</li>
|
| 77 | <li>The third, and any additional segments, represent the ID and any variables that will be passed to the controller.</p>
|
| 78 | </ol>
|
| 79 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 80 | <p>The <a href="../libraries/uri.html">URI Class</a> and the <a href="../helpers/url_helper.html">URL Helper</a>
|
| 81 | contain functions that make it easy to work with your URI data. In addition, your URLs can be remapped using the
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 82 | <a href="routing.html">URI Routing</a> feature for more flexibility.</p>
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 | <h2>Removing the index.php file</h2>
|
| 87 |
|
Derek Allard | c644128 | 2007-07-04 23:54:32 +0000 | [diff] [blame] | 88 | <p>By default, the <strong>index.php</strong> file will be included in your URLs:</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 89 |
|
| 90 | <code>www.your-site.com/<var>index.php</var>/news/article/my_article</code>
|
| 91 |
|
| 92 | <p>You can easily remove this file by using a .htaccess file with some simple rules. Here is an example
|
| 93 | of such a file, using the "negative" method in which everything is redirected except the specified items:</p>
|
| 94 |
|
| 95 | <code>RewriteEngine on<br />
|
| 96 | RewriteCond $1 !^(index\.php|images|robots\.txt)<br />
|
| 97 | RewriteRule ^(.*)$ /index.php/$1 [L]</code>
|
| 98 |
|
| 99 | <p>In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as
|
| 100 | a request for your index.php file.</p>
|
| 101 |
|
| 102 |
|
| 103 | <h2>Adding a URL Suffix</h2>
|
| 104 |
|
| 105 | <p>In your <dfn>config/config.php</dfn> file you can specify a suffix that will be added to all URLs generated
|
Derek Allard | c644128 | 2007-07-04 23:54:32 +0000 | [diff] [blame] | 106 | by CodeIgniter. For example, if a URL is this:</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 107 |
|
| 108 | <code>www.your-site.com/index.php/products/view/shoes</code>
|
| 109 |
|
admin | e7e1dcd | 2006-10-21 18:04:01 +0000 | [diff] [blame] | 110 | <p>You can optionally add a suffix, like <kbd>.html</kbd>, making the page appear to be of a certain type:</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 111 |
|
| 112 | <code>www.your-site.com/index.php/products/view/shoes.html</code>
|
| 113 |
|
| 114 |
|
| 115 | <h2>Enabling Query Strings</h2>
|
| 116 |
|
| 117 | <p>In some cases you might prefer to use query strings URLs:</p>
|
| 118 |
|
| 119 | <code>index.php?c=products&m=view&id=345</code>
|
| 120 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 121 | <p>CodeIgniter optionally supports this capability, which can be enabled in your <dfn>application/config.php</dfn> file. If you
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 122 | open your config file you'll see these items:</p>
|
| 123 |
|
| 124 | <code>$config['enable_query_strings'] = FALSE;<br />
|
| 125 | $config['controller_trigger'] = 'c';<br />
|
| 126 | $config['function_trigger'] = 'm';</code>
|
| 127 |
|
| 128 | <p>If you change "enable_query_strings" to TRUE this feature will become active. Your controllers and functions will then
|
| 129 | be accessible using the "trigger" words you've set to invoke your controllers and methods:</p>
|
| 130 |
|
| 131 | <code>index.php?c=controller&m=method</code>
|
| 132 |
|
| 133 | <p class="important"><strong>Please note:</strong> If you are using query strings you will have to build your own URLs, rather than utilizing
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 134 | the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed to work with
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 135 | segment based URLs.</p>
|
| 136 |
|
| 137 |
|
| 138 | </div>
|
| 139 | <!-- END CONTENT -->
|
| 140 |
|
| 141 |
|
| 142 | <div id="footer">
|
| 143 | <p>
|
| 144 | Previous Topic: <a href="index.html">Getting Started</a>
|
| 145 | ·
|
| 146 | <a href="#top">Top of Page</a> ·
|
| 147 | <a href="../index.html">User Guide Home</a> ·
|
| 148 | Next Topic: <a href="controllers.html">Controllers</a>
|
Derek Allard | c644128 | 2007-07-04 23:54:32 +0000 | [diff] [blame] | 149 | </p>
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 150 | <p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2007 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 151 | </div>
|
| 152 |
|
| 153 | </body>
|
| 154 | </html> |