blob: 8daef51a6d8deb7b78ac15ce64c80372891bbc0b [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Code Igniter User Guide</title>
<style type='text/css' media='all'>@import url('../userguide.css');</style>
<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
<script type="text/javascript" src="../scripts/nav.js"></script>
<script type="text/javascript" src="../scripts/prototype.lite.js"></script>
<script type="text/javascript" src="../scripts/moo.fx.js"></script>
<script type="text/javascript">
window.onload = function() {
myHeight = new fx.Height('nav', {duration: 400});
myHeight.hide();
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv='expires' content='-1' />
<meta http-equiv= 'pragma' content='no-cache' />
<meta name='robots' content='all' />
<meta name='author' content='Rick Ellis' />
<meta name='description' content='Code Igniter User Guide' />
</head>
<body>
<!-- START NAVIGATION -->
<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
<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>
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td><h1>Code Igniter User Guide Version 1.4.0</h1></td>
<td id="breadcrumb_right"><a href="../toc.html">Full Table of Contents</a></td>
</tr>
</table>
</div>
<!-- END NAVIGATION -->
<!-- START BREADCRUMB -->
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td id="breadcrumb">
<a href="http://www.codeigniter.com/">Code Igniter Home</a> &nbsp;&#8250;&nbsp;
<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
URLS
</td>
<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>
</tr>
</table>
<!-- END BREADCRUMB -->
<br clear="all" />
<!-- START CONTENT -->
<div id="content">
<h1>Code Igniter URLs</h1>
<p>By default, URLs in Code Igniter are designed to be search-engine and human friendly. Rather than using the standard "query string"
approach to URLs that is synonymous with dynamic systems, Code Igniter uses a <strong>segment-based</strong> approach:</p>
<code>www.your-site.com/<var>news</var>/<dfn>article</dfn>/<samp>my_article</samp></code>
<p class="important"><strong>Note:</strong> Query string URLs can be optionally enabled, as described below.</p>
<h2>URI Segments</h2>
<p>The segments in the URL, in following with the Model-View-Controller approach, usually represent:</p>
<code>www.your-site.com/<var>class</var>/<dfn>function</dfn>/<samp>ID</samp></code>
<ol>
<li>The first segment represents the controller <strong>class</strong> that should be invoked.</li>
<li>The second segment represents the class <strong>function</strong>, or method, that should be called.</li>
<li>The third, and any additional segments, represent the ID and any variables that will be passed to the controller.</p>
</ol>
<p>The <a href="../libraries/uri.html">URI Class</a> and the <a href="../helpers/url_helper.html">URL Helper</a>
contain functions that make it easy to work with your URI data. In addition, your URLs can be remapped using the
<a href="routing.html">URI Routing</a> feature for more flexibility.</p>
<h2>Removing the index.php file</h2>
<p>By default, the <strong>index.php</strong> file will be included in your URLs:
<code>www.your-site.com/<var>index.php</var>/news/article/my_article</code>
<p>You can easily remove this file by using a .htaccess file with some simple rules. Here is an example
of such a file, using the "negative" method in which everything is redirected except the specified items:</p>
<code>RewriteEngine on<br />
RewriteCond $1 !^(index\.php|images|robots\.txt)<br />
RewriteRule ^(.*)$ /index.php/$1 [L]</code>
<p>In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as
a request for your index.php file.</p>
<h2>Adding a URL Suffix</h2>
<p>In your <dfn>config/config.php</dfn> file you can specify a suffix that will be added to all URLs generated
by Code Igniter. For example, if a URL is this:
<code>www.your-site.com/index.php/products/view/shoes</code>
<p>You can optionaally add a suffix, like <kbd>.html</kbd>, making the page appear to be of a certain type:</p>
<code>www.your-site.com/index.php/products/view/shoes.html</code>
<h2>Enabling Query Strings</h2>
<p>In some cases you might prefer to use query strings URLs:</p>
<code>index.php?c=products&m=view&id=345</code>
<p>Code Igniter optionally supports this capability, which can be enabled in your <dfn>application/config.php</dfn> file. If you
open your config file you'll see these items:</p>
<code>$config['enable_query_strings'] = FALSE;<br />
$config['controller_trigger'] = 'c';<br />
$config['function_trigger'] = 'm';</code>
<p>If you change "enable_query_strings" to TRUE this feature will become active. Your controllers and functions will then
be accessible using the "trigger" words you've set to invoke your controllers and methods:</p>
<code>index.php?c=controller&m=method</code>
<p class="important"><strong>Please note:</strong> If you are using query strings you will have to build your own URLs, rather than utilizing
the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed to work with
segment based URLs.</p>
</div>
<!-- END CONTENT -->
<div id="footer">
<p>
Previous Topic:&nbsp;&nbsp;<a href="index.html">Getting Started</a>
&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
Next Topic:&nbsp;&nbsp;<a href="controllers.html">Controllers</a>
<p>
<p><a href="http://www.codeigniter.com">Code Igniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006 &nbsp;&middot;&nbsp; <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
</div>
</body>
</html>