views:

707

answers:

5

Hello Everyone,

Can someone help me with this. I'm feeling like I've been hitting my head against a wall for over 2 hrs now.

I've got Apache 2.2.8 + PHP 5.2.6 installed on my machine and the .htacces with code below works fine, no errors.

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

The same code on my hosting provider server gives me a 404 error code and outputs only: No input file specified. index.php IS there. I know they have Apache installed (cannot find version info anywhere) and they're running PHP v5.2.8.

I'm on windows xp 64-bit, they're running some Linux with php in cgi/fastcgi mode. Can anyone suggest what could be the problem?

PS. if that's important that's for CodeIgniter to work with friendly URLs.


Update1:

mod_rewrite is installed and on.

What I've noticed is that if I change in RewriteRule to /index.php?$1 (question mark instead of forward slash) it goes into an infinite loop. Anyway, using question mark isn't an option as CodeIgniter (required) is not going to work this way.

Homepage also works when I request index.php directly: example.com/index.php

I'm starting to think it might be apache thinking that once the trailing slash is added it is not a file anymore but a folder. how to change such a behaviour?


Update 2:

I was wrong.
Apache handles these urls correctly.
Requesting http://example.com/index.php/start/ (homepage) or any other valid address works.
Seems that Apache is just not forwarding the query for some reason.


Update 3:

Just to be clear what I'm trying to achieve.
I want to rewrite addresses like that:
http://www.example.com/something/ => http://www.example.com/index.php/something/ http://www.example.com/something/else/ => http://www.example.com/index.php/something/else/

A: 

It is very likely that the administrator of your host has disabled the ability to use Rewrite in .htaccess. They might not even have mod_rewrite installed.

Drop them an email and ask

Since this is a server configuration issue, perhaps you should ask at Server Fault

Edit (since you are sure that the server is configured correctly)

Have you considered tagging your RewriteCond with an end of line $?

RewriteCond $1 !^(index\.php|css|gfx|js|swf|robots\.txt|favicon\.ico)

Will (based on my limited knowledge) block any url that contains index.php, css, gfx ... at the start of a url. Because you don't have a $ at the end of the regexp, it will also block any urls that continue on from there...

I.e www.yourdomain.com/index.php/something is not redirected, same with www.yourdomain.com/js/something

Perhaps you want to add a $, which will require the url to end immediately after your regexp.

RewriteCond $1 !^(index\.php|css|gfx|js|swf|robots\.txt|favicon\.ico)$
Tom Leys
No. mod_rewrite is on. What I've noticed is that if I change in RewriteRule to /index.php?$1 (question mark instead of forward slash) it goes into an infinite loop.homepage also works when I request index.php directly:http://www.example.com/index.phpI'm starting to think it might be apache thinking that once the trailing slash is added it is not a file anymore but a folder. how to change such a behaviour?
Michal M
Re your edit. That's the point of not having $ at the end. So that any URLs starting with what's in the brackets are not being rewritten to index.php (inc. index.php and index.php/anything/) otherwise it will not work.
Michal M
Btw. I asked at SeverFault. not much luck there either and less answers/ideas.
Michal M
A: 

Maybe your server has AcceptPathInfo disabled that is essential for that kind of URL to work properly. Try to enable it:

AcceptPathInfo On


Ok, try this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php(/|$) index.php%{REQUEST_URI} [L]
Gumbo
nope. doesn't work.question updated.
Michal M
looked promising, but no luck. Error 404: No input file specified.
Michal M
A: 

mod_rewrite is a bit too smart for its own good, because it tries to figure out what sort of redirect it should be doing. In this case it looks to mod_rewrite like you're trying to redirect to a folder, so it looks for the folder and can't find it, hence the error.

Edit: Just to be perfectly clear I think your best bet is to change your rewrite rule to:

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

unless there is a very speciic reason why you want it to be a forward slash.

Edit 2: I see that you already tried this. The reason you're getting an infinite loop is because you have index.php in your rewrite condition. If you remove that you should be free of the infinite loop.

Jay Paroline
using ? mark isn't an option. CodeIgniter won't work this way.
Michal M
+1  A: 

Try if it works with a simpler RewriteCond; like one that rewrites only everything that isn't an existing file/folder/link:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.*)$ /index.php/$1 [R,L]
kkyy
this works for the homepage: example.com/, not for anything else like example.com/something/
Michal M
Oh, now I get it... you want to REDIRECT the requests instead of just REWRITING... (if I understood your update #3 correctly :) Try adding [R] into the end of the rewriterule, see my updated answer.
kkyy
no it's not a redirect, it is a rewrite.
Michal M
+1  A: 

I was beating my head up against this as well. I'm also installing Code Igniter.

The goocher was no RewriteBase. Here's my .htaccess:

DirectoryIndex index.php

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)

RewriteRule ^(.*)$ index.php?/$1 [L]
jray
THANK YOU!!! At last a good answer. Really appreciated.
Michal M