Welcome Guest, Not a member yet? Register   Sign In
Google ads + .htaccess + CI routing = 400 Bad Request
#1

[eluser]gautaml[/eluser]
I have a site that is very close to going live but I am having trouble embedding Googleads in the page.

The ad doesn't show up and Chrome debug shows this:
Image: Google Chrome debug

I put the ad script on a page on its own (not CI tied) and it shows up fine so I don't suspect it's the .htaccess but something with routing.

I have gone through several forum posts mostly those involving changing the config's uri_protocol (PATHINFO, etc) and enable_query_strings.

Treid all sorts of combos but nothing works.

Code:
$config['base_url']               = 'http://'.$_SERVER['HTTP_HOST'].'/';
$config['index_page']             = 'index.php';
$config['uri_protocol']           = 'REQUEST_URI';
$config['url_suffix']             = '';
$config['permitted_uri_chars']    = 'a-z 0-9~%.:_\-+@?=&';
$config['allow_get_array']        = TRUE;
$config['enable_query_strings']   = TRUE;

Here's my .htaccess
Code:
Header unset ETag
FileETag None

ExpiresActive On
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|css|js)$">
    ExpiresDefault "access plus 1 years"
</FilesMatch>

# Compress assets
<ifmodule mod_deflate.c="">
    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>

# Rewrite root
RewriteEngine On
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond $1 !^(index\.php)

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

And here's (some of) my routes.php

Code:
$route['default_controller']        = 'somepage';
$route['404_override']              = '';
$route['blog|/blog/(:any)']         = 'home/blog';
$route[':any']                      = 'somepage/catchall';

Any help?
#2

[eluser]John_Betong_002[/eluser]
If your page loads OK without Google Ads then this is the code that I use:
Code:
// ./application/view/_google_250x250.php
  &lt;?php /* google's script cut and pasted from Google Adsense */ ?&gt;
  &lt;script&gt;&lt;!--
  google_ad_client = "pub-03324275123XXXXX";
  /* 250x250, created 19/09/08 */
  google_ad_slot = "976264XXXX";
  google_ad_width = 250;
  google_ad_height = 250;
  //--&lt;/script&gt;

// ./application/controller/controller/your_controller.php
data['google_250x250'] = $this->load->view('_google_250x250',NULL,TRUE);

// ./application/views/your_view.php
&lt;?php echo $google_250x250;?&gt;

// or try this

&lt;?php include 'google_250x250.php';?&gt;
&nbsp;
&nbsp;
&nbsp;
#3

[eluser]gautaml[/eluser]
Well this is just interesting.

I was wondering if it could be badly formatted HTML since in my page rendernig process I process the page as this to strip out all tabs line breaks and comments:
Code:
preg_replace('/&lt;!--(.*)--&gt;/Uis', '', preg_replace('/\t+|\r\n|\n|\r/', '', $output));
Somewhere in tehre it was messing up the google code

Here's the original code:
Code:
<div id="adbar">
    [removed]&lt;!--
        google_ad_client = "ca-pub-xxxxxxxxx";
        /* 728x90 */
        google_ad_slot = "xxxxxxxxxx";
        google_ad_width = 728;
        google_ad_height = 90;
        //--&gt;
    [removed]
    [removed][removed]
</div>

If I remove all the HTML/JS comments the ads now come up.

Guess it was fine all along but just something I did. whoops. Smile

BTW thanks John, what you posted made me think twice about what I was doing Smile
#4

[eluser]John_Betong_002[/eluser]
Here is how I compress the final output:
Code:
//==============================================
function _compress(& $result='')
{
  $_SESSION['zzz_after']  = ''; // strlen($result);
  $_SESSION['zzz_before'] = strlen($result);

  $search = array(
      '/\>[^\S ]+/s',   //strip whitespaces after tags, except space
      '/[^\S ]+\</s',   //strip whitespaces before tags, except space
      '/(\s)+/s'        // shorten multiple whitespace sequences
      );
  $replace = array(
      '>',
      '<',
      '\\1'
      );
  $result = preg_replace($search, $replace, $result);

  // Problem: DOES NOT COMPRESS ADVERTS ?????
  // $hex=array("\x0D","\x0A");
  // $result=str_replace($hex,'',$result);

  $_SESSION['zzz_after'] = strlen($result);

  // $result .= '<p>Source code reduced by:'.sprintf('%6.3f', $_SESSION['zzz_after'] / $_SESSION['zzz_before']) .'%</p>';
  /*
  if(FALSE) // DABS this on the end after &lt;/body?&lt;/html>
  {
    $result .=  '<p>Source code: goes here'. jj
            .       'Before: '      . number_format($_SESSION['zzz_before'])  . jj
            .       'After: &nbsp;' . number_format($_SESSION['zzz_after'])   . jj
            .       'Saving: '      . number_format($_SESSION['zzz_before'] - $_SESSION['zzz_after']) .' bytes'
            .   '</p>';
  }
  */

  return $result;
}//endfunc
&nbsp;
&nbsp;
edit: view source on this page:
&nbsp;http://johns-jokes.com/2012-World-Cannot...cause.html




Theme © iAndrew 2016 - Forum software by © MyBB