Title: does not work with cgi, solution found
Last modified: August 20, 2016

---

# does not work with cgi, solution found

 *  [stockholmux](https://wordpress.org/support/users/stockholmux/)
 * (@stockholmux)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/does-not-work-with-cgi-solution-found/)
 * The plugin doesn’t function in a cgi environment. After deleting the 3.4 AtomPub
   files, I was getting 401 Unauthorized errors (even though it was working fine
   in the old implementation under WP 3.4). The authentication wasn’t properly being
   sent to the file after the rewrite. I had to do two things:
 * Change .htaccess from
    `RewriteRule . /index.php [L]` to `RewriteRule . /index.
   php [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]`
 * change class-wp-atom-server.php _authenticate()_ to:
 *     ```
       function authenticate() {
   
       		// if using mod_rewrite/ENV hack
       		// http://www.besthostratings.com/articles/http-auth-php-cgi.html
   
       		if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
       			list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) =
       				explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
       		} else if (isset($_SERVER['REDIRECT_REMOTE_USER'])) {
             //is this even possible now?
             //
       			// Workaround for setups that do not forward HTTP_AUTHORIZATION
       			// See http://trac.wordpress.org/ticket/7361
       			list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) =
       				explode(':', base64_decode(substr($_SERVER['REDIRECT_REMOTE_USER'], 6)));
       		} else if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
       			//because wpapp.php is virtual, the name of the server var has changed
       			list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) =
       				explode(':', base64_decode(substr($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 6)));
           }
   
       		// If Basic Auth is working...
       		if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
   
       			$user = wp_authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
       			if ( $user && !is_wp_error($user) ) {
       				wp_set_current_user($user->ID);
       				return true;
       			}
       		}
   
       		return false;
       	}
       ```
   
 * I tired to commit this to the svn, but I’m not really sure how this process works.
 * Cheers
 * [http://wordpress.org/extend/plugins/atom-publishing-protocol/](http://wordpress.org/extend/plugins/atom-publishing-protocol/)

The topic ‘does not work with cgi, solution found’ is closed to new replies.

 * ![](https://ps.w.org/atom-publishing-protocol/assets/icon.svg?rev=1908362)
 * [Atom Publishing Protocol](https://wordpress.org/plugins/atom-publishing-protocol/)
 * [Support Threads](https://wordpress.org/support/plugin/atom-publishing-protocol/)
 * [Active Topics](https://wordpress.org/support/plugin/atom-publishing-protocol/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/atom-publishing-protocol/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/atom-publishing-protocol/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [stockholmux](https://wordpress.org/support/users/stockholmux/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/does-not-work-with-cgi-solution-found/)
 * Status: not resolved