views:

56

answers:

2

I installed Apache for Windows. I bought CodeIgniter Professional and downloaded their source code. It said that I should put its .htaccess in the root folder of the website so I did. I set base URL to be http://127.0.0.1/kids/ where kids is the root folder of the website. It showed the homepage just fine. When I clicked on a link, it always gives the 404 error. It said, "The requested URL /index.php/welcome/cat/2 was not found on this server." I tried several possiblities of .htaccess in directories with no success. Inside the .htaccess, it instructs:

 RewriteEngine on
 RewriteCond $1 !^(index\.php|images|captcha|css|js|robots\.txt)
 RewriteRule ^(.*)$ /index.php/$1 [L]

Explain why it's not working at all? I also checked configs.php and it seems ok as well. config['index_page'] is set to blank. I removed the .htaccess file and still same problem except that it said, "The requested URL /kids/welcome/cat/2 was not found on this server."

Hours have been wasted on trying to get it working and I am losing patience.

Here's the instruction from CodeIgniter Professional:

"To make those folders accessible to CodeIgniter, you will also need to create a small .htaccess file in the root folder of your web site. Here's what that .htaccess file would look like. It basically contains instructions that allmvs certain files and folders to be viewable on the web site:

 RewriteEngine on
 RewriteCond $1 !^(index\.php|images|captcha|css|js|robots\.txt)
 RewriteRule ^(.*)$ /index.php/$1 [L]

If you are familiar with mod_rewrite in Apache, you will note that this rule ostensibly removes index.php from the URL of any destination. Below when you're configuring CodeIgniter (and particularly the config.php file), you'll see why this is a good idea. If you're not familiar with mod_rewrite in Apache, don't be too intimidated by this file. Basically, the .htaccess file sets forth a few rules, one of which removes index.php from all URLs. Other rules in the file allow the use of various other folders that you will need going forward (such as folders that contain CSS, JavaScript, Captcha files, and images)."

I did just as instructed... put the htaccess file in root folder and yet, it gave 404 error. If I remove htaccess file from the root folder, it shows homepage. If I add htaccess file, it gives 404 error. I moved htaccess and it didn't do anything to re-route. Obviously, the Apache understood the htaccess otherwise it wouldn't show the 404 error.

A: 

Try this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /index.php/$1 [NC,L]

Put this in the kids folder where index.php is.

Kieran Andrews
doesn't work either. :( I put that in root folder and after clicking on a link with URL, I get error saying, "The requested URL /index.php/welcome/cart/3 was not found on this server" on FF.
netrox
+1  A: 

It's possible that your routes aren't resolving correctly, but I'm not sure. I'd recommend the following steps.

First, I would just do away with using PATH_INFO for your CodeIgniter routing, as it's not necessary. Change your .htaccess file to this:

RewriteEngine On

RewriteCond $0 !^(index\.php|images|captcha|css|js|robots\.txt)
RewriteRule ^.*$ index.php [L]

Then, in your configuration, make sure that $config['uri_protocol'] is set to AUTO (the default, I believe) or REQUEST_URI.

Following that, the most likely cause is that your routes expect there to be a trailing slash on the URL. I don't know enough about CodeIgniter to know where that particular setting is configured, but you can cause your URLs to have a trailing slash with the following configuration directive:

$config['url_suffix'] = "/";

Edit: Make sure that mod_rewrite is working, as well. Try this at the top of your .htaccess file, after the RewriteEngine directive:

RewriteRule .* http://stackoverflow.com/ [L,R]

If you get redirected to Stack Overflow, at least we'll know that's working. If not, you aren't getting a 500 error, so the problem would lie with the .htaccess file, and in that case you should confirm that the corresponding <Directory> entry in your server configuration for where your site is located on disk has AllowOverride All set.

Edit: I should have known better about the forward slash, sorry about that. The problem occurs because of how mod_rewrite works in your per-directory (.htaccess) context.

Once your URL is rewritten, it is examined to determine what mod_rewrite should do with it. When your URL points to a local resource and contains a leading slash, mod_rewrite leaves it as-is. When it does not, it adds the per-directory prefix.

When it's left as-is, an internal redirect to /index.php, in this case, is assumed to be a fully-qualified URL from the host (localhost). So, the resource requested ends up being http://localhost/index.php. When the per-directory prefix is added, a later step in the rewrite engine attempts to remove the DocumentRoot from the path, if it's present. This leaves us with /kids/index.php, which is then passed to the internal redirect, and is resolved as expected.

Tim Stone
not working either. It also caused homepage to show 404 error. Did what you instructed... still nothing.
netrox
@netrox Hmm..interesting. See my edit and hopefully we can work from there.
Tim Stone
Tim, thanks for debug tip.. I added the line to reroute to stackoverflow and it did redirect without problems. (good debugging tip!) obviousy apache understands the htaccess file.
netrox
@netrox Ah, well that's good at least. Is `$config['index_page']` set to blank in your `config.php` file? Also, remove the initial slash from `/index.php` in the `.htaccess` file.
Tim Stone
FINALLY REMOVING THE INITIAL SLASH SOLVED THE PROBLEM!!!! Thank you Tim!!!! You the man! Makes no sense to me but at least it works! I will also report that oddity to Worx.
netrox
@netrox Glad to hear it's working. I've added an explanation of what goes on to cause this situation, too, in case you were curious.
Tim Stone