blob: 296271ed96949af075de93607b96399c31aee4ee [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001################
2CodeIgniter URLs
3################
4
5By default, URLs in CodeIgniter are designed to be search-engine and
6human friendly. Rather than using the standard "query string" approach
7to URLs that is synonymous with dynamic systems, CodeIgniter uses a
8**segment-based** approach::
9
10 example.com/news/article/my_article
11
12.. note:: Query string URLs can be optionally enabled, as described
13 below.
14
15URI Segments
16============
17
18The segments in the URL, in following with the Model-View-Controller
19approach, usually represent::
20
21 example.com/class/function/ID
22
23
24#. The first segment represents the controller **class** that should be
25 invoked.
26#. The second segment represents the class **function**, or method, that
27 should be called.
28#. The third, and any additional segments, represent the ID and any
29 variables that will be passed to the controller.
30
31The :doc::doc:`URI Class <../libraries/uri>` and the `URL
32Helper <../helpers/url_helper>` contain functions that make it
33easy to work with your URI data. In addition, your URLs can be remapped
34using the :doc:`URI Routing <routing>` feature for more flexibility.
35
36Removing the index.php file
37===========================
38
39By default, the **index.php** file will be included in your URLs::
40
41 example.com/index.php/news/article/my_article
42
43You can easily remove this file by using a .htaccess file with some
44simple rules. Here is an example of such a file, using the "negative"
45method in which everything is redirected except the specified items::
46
47 RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]
48
49In the above example, any HTTP request other than those for index.php,
50images, and robots.txt is treated as a request for your index.php file.
51
52Adding a URL Suffix
53===================
54
55In your config/config.php file you can specify a suffix that will be
56added to all URLs generated by CodeIgniter. For example, if a URL is
57this::
58
59 example.com/index.php/products/view/shoes
60
61You can optionally add a suffix, like .html, making the page appear to
62be of a certain type::
63
64 example.com/index.php/products/view/shoes.html
65
66Enabling Query Strings
67======================
68
69In some cases you might prefer to use query strings URLs::
70
71 index.php?c=products&m=view&id=345
72
73CodeIgniter optionally supports this capability, which can be enabled in
74your application/config.php file. If you open your config file you'll
75see these items::
76
77 $config['enable_query_strings'] = FALSE; $config['controller_trigger'] = 'c'; $config['function_trigger'] = 'm';
78
79If you change "enable_query_strings" to TRUE this feature will become
80active. Your controllers and functions will then be accessible using the
81"trigger" words you've set to invoke your controllers and methods::
82
83 index.php?c=controller&m=method
84
85**Please note:** If you are using query strings you will have to build
86your own URLs, rather than utilizing the URL helpers (and other helpers
87that generate URLs, like some of the form helpers) as these are designed
88to work with segment based URLs.