Welcome Guest, Not a member yet? Register   Sign In
CI not called when using mod_rewrite with PHP5 running as cgi
#1

[eluser]david_ais[/eluser]
My application makes heavy use of mod_rewrite to allow SEO friendly URLs to be internally redirected to the appropriate CI URL.

So .htaccess contains lots of lines like:
Code:
RewriteRule ^about\.html$ /index.php/pages/about [L]
That's been working fine on my internal system which runs PHP5 as an Apache module. And it runs fine on the live site when the site is running the ISP's default PHP4 which runs as cgi.

Because there's a part of my code that's PHP5 specific I used the facility on the ISP's server to switch the live site to run under PHP5. But as soon as I do that, the mod_rewrite entries appear to stop working. Other than the site's home page - which because it uses a default URL doesn't get filtered through mod_rewrite - every other page just returns the text:

"No input file specified"

- which I understand is the standard cgi processor response when it's called without a valid file name. In those cases, CI's main index.php file is never called.

The application itself runs fine with PHP5 on this server. So if I type in a CI url - e.g. the target url from the mod_rewrite example above '/index.php/pages/about' returns the expected page.

Given that mod-rewrite should perform an internal redirect and request the same page which works properly when accessed directly - everything seems to point to a problem with the interaction between mod_rewrite and the cgi processor when running PHP5. Unfortunately the ISP is being less than helpful. I don't think they know why this is happening but don't want to admit it!

Can anyone shed any light on this - and more importantly suggest a solution?

Regards

db
#2

[eluser]thurting[/eluser]
edit: sorry I misread your original post.

In any case, I don't understand why you are using those rewrite rules. CI's URLs are more search engine friendly than a URL in the form of about.html

I think you have to tell .htaccess that the file you are requesting does not exist and then run your rewrite.

Also, after looking on Google it seems there is a problem with the SCRIPT_FILENAME variable when using CGI. You should check it out.
#3

[eluser]david_ais[/eluser]
The example I gave is about the simplest one in .htaccess - purely to illustrate the problem. As it happens it just calls a static page.

Despite the simplicity of the example I gave - mod_rewrite is essential!


Regards

db
#4

[eluser]david_ais[/eluser]
[quote author="thurting" date="1194375288"]I think you have to tell .htaccess that the file you are requesting does not exist and then run your rewrite.[/quote]

If you mean by adding:
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

That doesn't make any difference. I tried!

All that's doing as just applying the rules that follow if a real file or directory of that name doesn't exist. The nature of the CI based applications is that the condition will always be met.

Regards

db
#5

[eluser]Sarfaraz Momin[/eluser]
Hi,
I have tons of such URLs and I use the routes available in codeigniter for such URLs. I just have one rule in my .htaccess and that is to remove the index.php file. Well to demonstrate this is how you can achieve it in codeigniter.

Code:
$route['aboutus\.html'] = "index.php/pages/aboutus";

I found that codeigniter gave me a lot more flexibility and power when using the routes for clean and SEO friendly URLs.

Hopes this make sense. Let me know if you have any queries.

Good Day !!!
#6

[eluser]thurting[/eluser]
Yes, but why are you rewriting all of your pages with mod_rewrite? Why not just send * to index.php and let CI's internal router take care of controller/method calls?
#7

[eluser]david_ais[/eluser]
[quote author="thurting" date="1194375288"]Also, after looking on Google it seems there is a problem with the SCRIPT_FILENAME variable when using CGI. You should check it out.[/quote]

I've seen vague references to this - both in the forums here and also on Google. The suggestion seems to be that for some reason the value of $SERVER['SCRIPT_FILENAME'] doesn't point to the main CI index.php file. Or that somehow when running with PHP5 as cgi that it's value is changed in some unspecified way. A key question though is - why is it different as a result of a mod_rewrite internal direct compared with directly accessing a URL?

In any case the big difficulty with this is that the way the problem manifests is that it never actually runs CI's index.php So there's a bit of a problem in discovering what $SERVER['SCRIPT_FILENAME'] is set to as the only way I can think of to find out is to add some code the the PHP file to log the value!!

Logically this might be a good line of enquiry. But in practice - how do I find out what it's set to? And if it's wrong how do I change it anyway?

Googling for further info has so far failed to address those questions


Regards

db
#8

[eluser]david_ais[/eluser]
[quote author="Sarfaraz Momin" date="1194377400"]Hi,
I have tons of such URLs and I use the routes available in codeigniter for such URLs. I just have one rule in my .htaccess and that is to remove the index.php file. Well to demonstrate this is how you can achieve it in codeigniter.

Code:
$route['aboutus\.html'] = "index.php/pages/aboutus";
[/quote]

That's a useful technique. Thanks

Like you I want to remove index.php from the URL which means I still have to have a single line in .htaccess to rewrite the URL to put the index.php back in for CI. And that's enough to trigger the problem. So this doesn't help.

Regards

db
#9

[eluser]Sarfaraz Momin[/eluser]
Hi,
I do not think the problem is with PHP 5 and mod_rewrite. I have one environment where I have PHP 5.2.4 running as fastcgi and it works like a charm. Is there something you would like to tell us about your environment which might help??
#10

[eluser]david_ais[/eluser]
[quote author="Sarfaraz Momin" date="1194380869"]I do not think the problem is with PHP 5 and mod_rewrite. I have one environment where I have PHP 5.2.4 running as fastcgi and it works like a charm. Is there something you would like to tell us about your environment which might help??[/quote]

I can't get away from the conclusion that whatever URI mod_rewrite is passing to the cgi PHP processor after the internal redirect - for some reason it's pointing to the wrong place so CI doesn't run.

Where do I start with the environment! It's PHP5.2.4 running via cgi.
What information would be helpful? I could post the output of phpinfo - but that's just a bit OTT!

Regards

db




Theme © iAndrew 2016 - Forum software by © MyBB