2011-04-15 115 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