Google Adwords and CodeIgniter GET Variable Callback URL - codeigniter

I am trying to implement Google Adwords with a website that has been developed using CodeIgniter, I believe it requires a "200" status code when they add a GET variable to the URL.
I've been getting emails from Google saying that it's receiving a 404 status code when it goes to my URL. When I try to add ?test=test to the end of my URL it does in fact return a 404:
Through my google searches, I have found this useful link:
http://codeigniter.com/forums/viewthread/154153/#746115
Which states I need to change my config to include these:
$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = TRUE;
Before my uri_protocol was set to "REQUEST_URI". I have tested with ?test=test and it does work! But now all my links are not working, when I switch it to PATH_INFO, what do I need to do to fix my links?
Right now I am using Mod Rewrite to shorten the URLs so that the addresses are like mydomain.com/blog, mydomain.com/about, and my controller just points to the appropriate view. Should I not change my uri_protocol, if so how can I include a GET variable and NOT get a 404?
Any advice would help thank you!
UDPATE: Here's my htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

If you are using CodeIgniter 2, you can do:
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;

You need to do the following
1- $config['enable_query_strings'] = TRUE;
2- $config['permitted_uri_chars'] = 'a-z 0-9~%.:_-\?=&';
AND remove the "?" from your htaccess file.
3- RewriteRule ^(.*)$ index.php/$1 [QSA,L]

Related

CodeIgniter: keep index.php in url and hide the rest

greatings...
Question :
How to keep index.php in url and hide everything else so my url look like (www.base_url.com/index.php) for every page?
Details :
i've searched but i only got how to remove index.php, i think im the only one who want to keep it...lol
im using codeigniter 3 to working on web based app human resource managemen soo i dont need SEO url since the app only accessed by internal employees. i like to make the url clean, only show base_url and the index.php for every page. please show me how to config codeigniter like i need...thank you
Use .htaccess like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
This will look more cleaner than with index.php. The URL will be like this www.your_baseurl.com/users
and edit your config.php file to use URI like this:
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
You can use your route like this:
$route['users'] = 'home/users';

Getting default (not CI) 404 for all pages

I am trying to develop using CI for the first time. I have not changed any defaults WRT paths, .htaccess, etc. Two hours ago I was able to load pages; now I am not. All of this is on a virtual box running on my Mac, and I had been messing with the virtualbox settings in order to try to get the web pages to load while connected to a VPN (did not succeed). At no time did I edit any files on the VM, whether for connect settings or related to CI and my project.
Giving up with the VPN, I returned to my project to continue with code enhancements. Only now, as my title suggests, nothing will load. The default "It works" page loads so I know nginx is responding to requests. I don't get the Code Igniter 404 page -- I get the generic:
Not Found
The requested URL /index.php/c_login/ was not found on this server.
In this example, c_login extends CI_Controller and displays a view in its index function.
Based on my searches:
My config.php contains $config['uri_protocol'] = 'REQUEST_URI';
There was no .htaccess file previously, and that is still the case
I don't understand the bit about capital first letter in my controllers, as I've had lower case since I started the project and had no problem
Except for a minor change to a view file (not trying to load that one right now), nothing has changed since the last pull from the git server
I had left the welcome_message view and welcome controller in place when starting this project, and that no longer works either. Any ideas? I am at a complete loss.
Change this
In your config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
then in .htaccess(this should be place out side of application folder)
RewriteEngine on
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
EDIT 01
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Joomla not finding index.php after

I had turned Use URL rewriting to ON
Added some code in to the ht access file and this never worked.
I then turned off url rewriting and removed the code and now when I try to go to the website I am getting a 404 error.
I can still access /administration
the website is www2.daxtra.com
the page it should find is http://www2.daxtra.com/index.php/home
Does anyone have any ideas what has happened?
This was the code I added:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Thanks
Right, I've done a small test.
To get what you want, you need to following:
htaccess.txt (you don't need a .htaccess file)
Search Engine Friendly URLs set to On
Use URL rewriting set to Off
You finally need to ensure that your Homepage menu items it set to a specific component such as an article or something else, not an Alias
This will ensure that you get example.com/index.php/home
Hope this helps

domain.com/username mod rewrite in codeigniter

I'm new to mode rewrite thing. Started off with codeigniter a couple of days back and trying to get a hand at it. I'm developing a website which needs domain.com/USERNAME for better SEO results. But I'm unable to figure out as to what mod rewrite I should write to achieve this. I already have removed the index.php entry in config and my base url is http://127.0.0.1/myproject/. (I'm using XAMPP)
So I have to search for username in this format
http://127.0.0.1/myproject/USERNAME
and return the corresponding page. My current mod rewrite file goes as follows :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Any suggestions?
Thank you for your help :-)
http://daparky.com/codeigniter-vanity-username-personalised-urls/
this should solve your problem.

jquery.ajax in codeigniter

I am having a problem in implementing jquery.ajax in codeigniter. I want to send the control to a specific function of a controller. I am setting the url in my javascript function like this
var url='<?php echo('First/index');?>';
var ajaxoptions={url:url,success:submit_ajax_response};
First is my controller and index is my function where I want to send the control. When I click on the event on which it is called the following url is formed
http://localhost/codeigniter/First/index
The URL is fine but it is generating the error of 404. I have done such kind of operations various times in zendframework but unable to accomplish this job in codeigniter. I have noticed one thing that if I add index.php in the url it works fine. By adding index.php the url becomes like
http://localhost/codeigniter/index.php/First/index
I am astonished how to remove index.php from route file. I have only two lines in route.php file
$route['default_controller'] = "First";
$route['404_override'] = '';
I have already made my controller as the default controller.
Am I doing correct? What is the problem and how to accomplish this job`
You need to check a couple of things. First, in /application/config/config.php make sure index file is set to this:
$config['index_page'] = '';
Second, make sure you have correct .htaccess. This should be at the root of your public directory (same place as your index.php):
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options FollowSymLinks
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I notice the part that is missing form your URL is the "index.php" thing that CodeIgniter has.
Change your code to this: (You need URL helper, so load that before this):
var url="<?php echo (index_page() . 'First/index');?>";
var ajaxoptions={url:url,success:submit_ajax_response};
index_page returns your site "index" page, as specified in your config file.
In order to remove index.php from your CodeIgniter links see here.

Resources