CGI Error (WordPress)

Topics: Developer Forum, User Forum
Dec 11, 2009 at 11:00 PM

Getting the following error:

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.

iirf.ini:
RedirectRule ^/index\.php/(.*)$ /$1 [I,R=301]
RewriteRule ^/(?!index\.php|wp-)(.*)$ /index.php/$1 [I,L]

I'm able to view pages under the wp- directories using these rules. If I replace the above with:

RewriteRule . /index.php [I]

Public pages are then visible, but missing all styling from css. However, then unable to reach pages under wp- directories.

Environ:
IIS6
Iirf.dll v2.0.1.15

What am I doing wrong?

Coordinator
Dec 12, 2009 at 2:39 AM

I don't know what you're doing wrong.

The CGI problem - I don't know what that is, and I don't think I can help you. I'm not sure how it's related to IIRF.

You described an iirf.ini and said you're able to see the pages under the wp- directories.  So... why did you change IIRF?  What problem are you trying to solve by changing IIRF.ini? 

You then describe the results you got after changing IIRF.ini, and those results seem not so good.  why not go back to the one that worked?

??  It's obvious I don't understand the problem. 

 

Dec 16, 2009 at 9:33 PM
Edited Dec 16, 2009 at 9:34 PM

Sorry, I may not have be clear. Individually, each set of the rules above have desired and undesirable results. I'm thinking I need some combination of these to make WordPress happy.

When using only this rule:

RewriteRule . /index.php [I]

I can ONLY view the Home page, but no styles from the linked stylesheet are applied to the page. Stylesheet is located in /wp-content/themes/default/style.css. Clicking on any links to other pages, public ( /ANY-PAGE) or admin (under /wp-admin directory) results in the Home page redisplaying. For example, clicking on Site Admin changes the url to domain.com/wp-admin, but the Home page is what gets redisplayed.

This seems to indicate that a rule is necessary to read files under /wp-[...] directories.

When using these rules:

RedirectRule ^/index\.php/(.*)$ /$1 [I,R=301]
RewriteRule ^/(?!index\.php|wp-)(.*)$ /index.php/$1 [I,L]

Pointing the browser to the domain name without appending /index.php results in 404 page error ("The page cannot be found"). When pointing to /index.php, the Home page displayed properly with all styles applied. All site admin pages are also accessible and display properly. However, pointing the browser to any pages besides index.php or pages under /wp-[...] directories results in the CGI Error: The specified CGI application misbehaved by not returning a complete set of HTTP headers.

The WordPress app at this domain has Permalink Settings set to Custom Structure = /%postname%/

IIRF is working exceptionally well on Drupal sites on the same server. Not sure if it matters, but both Drupal and WordPress sites are using FatsCGI handler.

Does this description help define the problem? What can I try?

Thanks.

Coordinator
Dec 17, 2009 at 2:53 AM
Edited Dec 17, 2009 at 2:56 AM

Yes, that's clearer.

I think you need to understand and clearly state the requirements, and then you also need to understand how IIRF rules can fit your requirements. I think your requirements are:

  1. empty URLs should get rewritten to index.php (Default).  Rewrite means no update in the browser bar
  2. any URL that starts with index.php should get Redirected (R=301), so that the index.php is stripped.  Redirect means update the browser bar.
  3. any URL that does not start with wp- , should get rewritten to index.phpXXX, where XXX is replaced with the original URL.

That seems like 3 rules to me.

# Reqmt 1:  rewrite empty URL paths to index.php, the main page
RewriteRule ^/?$   /index.php  [L]

# Requirement 2: if index.php is present, redirect to strip it
RedirectRule ^/index\.php/(.*)$  /$1 [I,R=301]

# Requirement 3: for any URL that does not begin with wp-, rewrite it to prepend index.php/
RewriteRule ^/(?!wp-)(.+)$ /index.php/$1 [I,L]

# All other URLs pass through unchanged

 I don't know if those requirements are appropriate for Wordpress.  I don't know wordpress, and I'm sort of guessing about the requirements.  But I'm pretty sure the rules I wrote fit the requirements.

The problem with "complete set of HTTP Headers" is mysterious. I don't know what might cause that but I'm hoping it will go away once you get the other rules lined up.

Dec 17, 2009 at 4:05 AM
Edited Dec 17, 2009 at 4:06 AM

Sorry for you having to spend some time on this item. I was trying to use IIRF rewrite rules for WordPress found in other blogs hoping for a semi-plug-and-play solution. When setting IIRF up with the rules and found rewrite was not working, I attributed the problem to IIRF or the rules. However, I found that the problem was in how php was executed. There were some FastCGI issues. They have been resolved with the use of FastCGI 1.5-Beta which is more forgiving with HTTP header requirements. WordPress is now working well with IIRF for rewrite.

Thank you for your help.

Coordinator
Dec 17, 2009 at 4:39 AM

No problem.

Can you please post information about your Wordpress configuration and the IIRF rules you settled on, so that other wordpress people will know what to do?

 

Aug 5, 2010 at 4:52 PM
Edited Aug 5, 2010 at 4:57 PM

Hi.

I've been trying to get the IIRF module to achieve the same objective as "topnetwork" (remove "index.php/" from the address path), but with no success.

I use IIRF elsewhere successfully (e.g. domain name rewriterules). Our Wordpress blog is running on IIS 6, configured as an application (named "news") underneath the main site. This gives it the /news/... path prefix.

I've tried the three stage rules Cheeso added above, but these don't work with this setup. The two-line sample by John Sheehan seems to work for him, but it fails for me. Not sure if this is because our blog isn't the root site but in an app folder.

My IIRF file:

## ---------- 
# Blog pretty URLs
# Objective: remove the "index.php/" from the path # e.g. www.mydomain.com/news/index.php/category/business-psychology # should become: www.mydomain.com/news/category/business-psychology # and www.mydomain.com/news/index.php/migraine-awareness/ (an individual post item)
# should become: www.mydomain.com/news/migraine-awareness/ # # Sample based on http://john-sheehan.com/blog/using-iirf-url-rewriting-on-iis6-with-wordpress/ # Note that the Permalink option for Wordpress must be set to Custom, with setting /%postname%/ # This allows the RSS feed to list the blog links without adding "index.php". RedirectRule ^/news/index\.php/(.*)$ /news/$1 [I,R=301] # must include index\.php in the first group or RSS feed gets broken. # Feed format example: /news/index.php?feed=rss2&cat=3 RewriteRule ^/news/(?!index\.php|wp-|xmlrpc)(.*)$ /news/index.php/$1 [I,L] # # Alternative approach - Test based on Cheeso's posting: # Reqmt 1: rewrite empty URL paths to index.php, the main page #RewriteRule ^/news/?$ /news/index.php [L] # Requirement 2: if index.php is present, redirect to strip it #RedirectRule ^/news/index\.php/(.*)$ /news/$ [I,R=301] # Requirement 3: for any URL that does not begin with wp-, rewrite it to prepend index.php/ # must include index\.php in the first group or RSS feed gets broken. #RewriteRule ^/news/(?!index\.php|wp-|xmlrpc)(.+)$ /news/index.php/$ [I,L] ## ----------

Any ideas what I might be missing? - Regex is definitely not my forte! Thanks.

Aug 5, 2010 at 5:17 PM

I continued to experience issues with IIRF and Wordpress. I'm sure I could have got it all to work, but did not any more time to troubleshoot. You may find some helpful information here:

http://john-sheehan.com/blog/using-iirf-url-rewriting-on-iis6-with-wordpress/

I do use IIRF for all other PHP apps, e.g., Drupal, and with custom PHP. However for Wordpress, I use the url rewrite ISAPI filter found here:

http://www.binaryfortress.com/wordpress-url-rewrite/

I hope this helps.

Aug 6, 2010 at 9:28 AM
Edited Aug 6, 2010 at 9:34 AM

Thanks for the tip about the other ISAPI option.  I'll give it a go, but the support forum seems to indicate IIRF is recommended even by the author of the Binary Fortress tool!

When I awoke this morning I realised I should correct my objective from my original post. 

This should actually be to insert index.php invisibly to the address between news/ and the post name for the Wordpress engine (i.e. server side) use.

With Wordpress' Custom Permalinks option set to "/%postname%", Wordpress itself will remove the index.php part of the paths it creates, so that bit is simple.

However, when trying to access the posts via these links, they cannot be found directly, but need the inclusion of index.php/

Example:

  1. www.mysite.com/news/index.php/category/business-psychology/
  2. www.mysite.com/news/category/business-psychology/

In item 1 we have an address that will work irrespective of the Wordpress custom permalink setting (and ignoring the dummy domain of course). 
In item 2 we have the address that Wordpress generates with the custom permalink set to "/%postname%", but can't actually access unless you edit it to add in the "index.php/" part.

The third ReWriteRule that Cheeso posted describes the objective I want to achieve, but it doesn't seem to work.  Again, I don't know if this
is because our Wordpress install is as a sub-directory (/news/) of our main site.  Of course, I may have incorrectly adjusted the Regex during my adaptation to
our paths, by the addition of "/news/".