English 中文(简体)
CodeIgniter configuration with mod_rewrite, xampp and windows
原标题:

I m a noob to CodeIgniter and am trying to figure out the configuration for an app I m building. Something is wrong with my setup.

I m running XAMPP on Windows and am using an alias directory to point to the applications directory. In other words: "http://localhost/app_name/ " points to the root directory of the application. It all seems to work well until I do the .htaccess for mod_rewrite. Then every time I try to go to a controller I get pitched back to the xampp root.

My config is:

Directories

/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";

I should also state that the app_name directory is an alias for a different drive than the apache root.

Apache Root: c:xampphtdocs
App_name: d:projectsapp_namedevelopment

The alias is:

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> 

Thanks in advance for the help... And if you don t mind please "explain" what you re doing when you answer with code. I want to know what I m doing wrong. If you can help me with this I ll buy you a beer (via PayPal). This is frustrating.

最佳回答

Success!!

I finally managed to get URL rewrite working and what a long arduous journey it was. Here is what I got working finally. Take note that there is no backslash on the RewriteBase. Very interesting given what I ve read. Thanks to everybody who tried to help.

# 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]
问题回答
RewriteBase /

in your .htaccess should be

RewriteBase /app_name/

to specify which directory it is..

If your using XAMPP on a local machine, your should use internal rather than mod_rewrite.

It will load your pages under the alias name.

it took me a while to figure that out - apparently you should use mod_rewrite on remote servers to achieve the same thing.

First, a question. Is your $system_folder variable really set to:

$system_folder = "@codeigniter";

or was that a nerf from the weird (to me) way SO uses markdown? If it is, remove the @. It is an invalid character for directory/file names.

Next, I believe your RewriteBase should be /, since you use an alias in Apache, but don t quote me on that.

I personally use the .htaccess format supplied here: CodeIgniter URLs in the User Guide; under the heading Removing the index.php file. There are many ways to do it, however. A quick Google search yields a couple thousand.

Do you have mod_rewrite enabled? Check the forum post here.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签