2011-04-15 114 views

回答

0

index.php和一些.htaccess招我用这个代码(Cl 2)的:

# Deny OR Allow Folder Indexes. 
# Since we disable access to PHP files you 
# can leave this on without worries. 
# OR better yet, create a .htaccess file in 
# the dir you want to allow browsing and 
# set it to +Indexes 
Options -Indexes 

Options +FollowSymLinks 

# Set the default file for indexes 
DirectoryIndex index.php 

<IfModule mod_rewrite.c> 
    # mod_rewrite rules 
    RewriteEngine on 

    # If a controler can't be found - then issue a 404 error from PHP 
    # Error messages (via the "error" plugin) 
    # ErrorDocument 403 /index.php/403/ 
    # ErrorDocument 404 /index.php/404/ 
    # ErrorDocument 500 /index.php/500/ 

    # Deny any people (or bots) from the following sites: (to stop spam comments) 
    # RewriteCond %{HTTP_REFERER} nienschanz\.ru [NC,OR] 
    # RewriteCond %{HTTP_REFERER} porn\.com 
    # RewriteRule .* - [F] 
    # Note: if you are having trouble from a certain URL just 
    # add it above to forbide all visitors from that site. 

    # You can also uncomment this if you know the IP: 
    # Deny from 192.168.1.1 

    # If the file is NOT the index.php file 
    RewriteCond %{REQUEST_FILENAME} !index.php 
    # Hide all PHP files so none can be accessed by HTTP 
    RewriteRule (.*)\.php$ index.php/$1 

    # If the file/dir is NOT real go to index 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [QSA,L] 

</IfModule> 

# If Mod_ewrite is NOT installed go to index.php 
<IfModule !mod_rewrite.c> 
    ErrorDocument 404 index.php 
</IfModule> 

PS我认为我没有很清楚地知道.php文件的问题。但是,如果你还没有准备好,你想看看native CI routing system它可以与另一种方法解决你的问题)

+0

@kradmiy其实我有2个应用程序运行上面提到的2个应用目前测试设置 我使用中提到的国防部重写规则下codeigniter,它们对于index.php位于服务器根目录中的主应用程序正确工作。 现在我已经创建了更多的根目录city1和city2中的文件夹,每个文件夹都有自己的index.php文件,但是当我在浏览器中访问url时,它们似乎重定向到根目录下的主应用程序 – user160108 2011-04-15 10:16:01

+1

,像“城市/搜索”这样的网址,实际上并没有在你的服务器上存在这样的目录。例如,如果你的网址中的搜索段长度不变,那么你可以调整'.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

+0

@kradmiy可我还做这样的事情 $路线[“:任何”] =“城市/ switch_city” 所以路由器穿城而过控制器通过每个URL,并从那里我调用相应的控制器和方法 威尔这项工作 – user160108 2011-04-15 13:12:31

0

让我们开始与我们的大网址:

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