[英]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.