2009-12-02 24 views
1

我是CodeIgniter的noob,正試圖弄清楚我正在構建的應用程序的配置。我的設置有問題。使用mod_rewrite,xampp和windows進行CodeIgniter配置

我在Windows上運行XAMPP,並使用別名目錄指向應用程序目錄。換句話說:「http://localhost/app_name/」指向應用程序的根目錄。這一切似乎工作得很好,直到我爲mod_rewrite執行.htaccess。然後每次我嘗試去控制器時,我都會回到xampp根目錄。

我的配置是:

目錄

/app_root 
/app_root/codeigniter // where code igniter is located. 
/app_root/main  // where the main app is located. It' the applications 
         // directory cut from code igniter and renamed. 

的.htaccess

<IfModule mod_rewrite.**so**> 
RewriteEngine On 
RewriteBase **/app_name/** 
RewriteCond %{REQUEST_URI} ^codeigniter.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?/$1 [L] 
</IfModule> 
<IfModule !mod_rewrite.c> 
ErrorDocument 404 /index.php 
</IfModule> 

的index.php

$system_folder = "@codeigniter"; 
$application_folder = "main"; 

APP_NAME /主/配置/ config.php文件

$config['base_url'] = "http://localhost/app_name/"; 
$config['index_page'] = ""; 

APP_NAME /主/配置/ routes.php文件

$route['default_controller'] = "welcome"; 

我還要指出的APP_NAME目錄是別名爲apache根目錄以外的驅動器。

Apache Root: c:\xampp\htdocs\ 
App_name: d:\projects\app_name\development\ 

別名是:提前爲幫助

Alias /app_name "d:/projects/app name/development" 
<Directory "d:/projects/app name/development"> 
    Options Indexes FollowSymLinks ExecCGI 
    AllowOverride All 
    Order allow,deny 
    Allow from all 
</Directory> 

謝謝...如果你不介意的話,請「解釋」當你的代碼回答你在做什麼。我想知道我做錯了什麼。如果你能幫助我,我會給你買一瓶啤酒(通過PayPal)。這令人沮喪。

回答

5

成功!

我終於設法讓URL重寫工作,這是一個漫長的艱難旅程。這是我最終做的。請注意,RewriteBase上沒有反斜槓。給我讀過的東西非常有趣。感謝所有試圖提供幫助的人。

# Options 
Options -Multiviews 
Options +FollowSymLinks 

#Enable mod rewrite 
RewriteEngine On 
#the location of the root of your site 
#if writing for subdirectories, you would enter /subdirectory 
RewriteBase /app_name 

#Removes access to CodeIgniter system folder by users. 
#Additionally this will allow you to create a System.php controller, 
#previously this would not have been possible. 
#'system' can be replaced if you have renamed your system folder. 
RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

#Checks to see if the user is attempting to access a valid file, 
#such as an image or css document, if this isn't true it sends the 
#request to index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

#This last condition enables access to the images and css 
#folders, and the robots.txt file 
RewriteCond $1 !^(index\.php|images|robots\.txt|css) 

RewriteRule ^(.*)$ index.php?/$1 [L] 
1
RewriteBase/

在你的.htaccess應該

RewriteBase /app_name/ 

指定是哪個目錄..

+0

這並沒有幫助...相同的行爲。 – 2009-12-03 02:16:39

+0

我把mod_rewrite.c改成了mod_rewrite.so,現在我得到了找不到對象的錯誤信息。當我嘗試訪問http:// localhost/app_name/welcome/ 時,我還應該聲明,app_name目錄是與apache根目錄不同的驅動器的別名。 Apache的根目錄:C:\ XAMPP \ htdocs中\ APP_NAME:d:\項目\ APP_NAME \研發\ 別名是: 別名/ APP_NAME 「d:/項目/應用程序名稱/發展」 <目錄「d:/項目/應用程序名稱/開發」> 選項指標的FollowSymLinks ExecCGI 設置AllowOverride所有 訂購允許,拒絕 所有 – 2009-12-03 22:50:30

0

首先一個問題。是您的$system_folder變量確實設置爲:

$system_folder = "@codeigniter"; 

或者是從怪異的nerf了(我)方式,以便使用降價?如果是,請刪除@。它是目錄/文件名稱的無效字符。

接下來,我相信應該RewriteBase/,因爲你使用了Apache的別名,但不可以引用我這句話。

我個人使用這裏提供的.htaccess格式:CodeIgniter URLs in the User Guide;在標題下刪除index.php文件。然而,有很多方法可以做到這一點。 A quick Google search產生幾千。

您是否已啓用mod_rewriteCheck the forum post here

+0

感謝邁克允許,我試圖將其改名爲「CI」,而不是,我得到了@codeigniter從另一個教程。仍然沒有工作。我在想這是我的機器,所以我想嘗試爲我的個人網站創建一個,看看是否是這樣。 – 2009-12-05 17:39:23

2

如果您在本地機器上使用XAMPP,您應該使用internal而非mod_rewrite

它會加載您的網頁下的別名。

我花了一段時間才弄清楚 - 顯然你應該在遠程服務器上使用mod_rewrite來實現同樣的目的。

相關問題