让我们开始与我们的大网址:
http://mycustomproject.com/index.php/webpages/view/my-url-title-of-the-post
的第一件事情,你通常做你的Codeigniter项目是从URL中删除index.php文件。要做到这一点的话,那也是相当简单:
第一步
此代码.htaccess文件添加到您的项目的根。
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase/
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
创建的.htaccess的文件后,你的项目结构必须是这样的:
website_folder/
----应用/
----资产/
---- system/
---- user_guide/
---- htaccess的< -------------------------
--- - 的index.php
---- LICENSE.TXT
第二步
现在去:应用程序/配置/ config.php文件并改变: $配置[ 'index_page'] ='索引。PHP的“;
到 $ config ['index_page'] ='';
所以,现在你的URL看起来像这样:
http://mycustomproject.com/webpages/view/my-url-title-of-the-post
@kradmiy其实我有2个应用程序运行上面提到的2个应用目前测试设置 我使用中提到的国防部重写规则下codeigniter,它们对于index.php位于服务器根目录中的主应用程序正确工作。 现在我已经创建了更多的根目录city1和city2中的文件夹,每个文件夹都有自己的index.php文件,但是当我在浏览器中访问url时,它们似乎重定向到根目录下的主应用程序 – user160108 2011-04-15 10:16:01
,像“城市/搜索”这样的网址,实际上并没有在你的服务器上存在这样的目录。例如,如果你的网址中的搜索段长度不变,那么你可以调整'.htaccess'规则来将这个网址重写为CI index.php,并在url中传递'city/search'作为参数(你可以在控制器中获取这些数据并根据收到的值调用合适的方法)。 'RewriteCond%{REQUEST_URI}^/(。*)/ search /(.*)$ RewriteRule ^(。*)$ /inde.php?uri=$1 [L]'GET'中有'url' var提供数据的阵列。 – 2011-04-15 11:43:39
@kradmiy可我还做这样的事情 $路线[“:任何”] =“城市/ switch_city” 所以路由器穿城而过控制器通过每个URL,并从那里我调用相应的控制器和方法 威尔这项工作 – user160108 2011-04-15 13:12:31