簡體   English   中英

帶有mod_rewrite,xampp和Windows的CodeIgniter配置

[英]CodeIgniter configuration with mod_rewrite, xampp and 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 / main / config / config.php

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

app_name / main / config / 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)。 這真令人沮喪。

成功!!

我終於設法使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]

如果在本地計算機上使用XAMPP,則應使用internal而不是mod_rewrite

它將以別名名稱加載您的頁面。

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

RewriteBase /

在您的.htaccess文件中

RewriteBase /app_name/

指定它是哪個目錄。

首先,一個問題。 您的$system_folder變量是否真的設置為:

$system_folder = "@codeigniter";

還是那是一種怪異的(對我而言)使用降價促銷的書呆子? 如果是,請刪除@ 這是目錄/文件名的無效字符。

接下來,我相信您的RewriteBase應該為/ ,因為您在Apache中使用了別名,但不要在此引用我。

我個人使用此處提供的.htaccess格式: 用戶指南中的CodeIgniter URL 在“ 刪除index.php文件 ”標題下。 但是,有很多方法可以做到這一點。 快速的Google搜索可產生數千個結果。

您是否啟用了mod_rewrite 在此處查看論壇帖子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM