CodeIgniter disallowed characters using QUERY_STRING uri protocol - ajax

I've been working on a project and been testing it on localhost as well as on a free web server, and it has worked perfectly. However when I got my own domain and web hosting service the site stopped working.
To make it work I had to change the RewriteRule to
RewriteRule ^(.*)$ /index.php?$1 [L]
and then setting
$config['uri_protocol'] = 'QUERY_STRING';
However, links like this one;
http://www.mydomain.com/ajax/membersearch/anemail%40here.com
used to work, but now it returns a CI error saying "The URI you submitted has disallowed characters."
This worked perfectly before I had to change the RewriteRule and uri_protocol, so I'm wondering what is making it not work now, and how to fix it?

You may need to update your config.php file. Replace the default permitted characters setting with the following line:
$config['permitted_uri_chars'] = 'a-z 0-9~%\.\:_\+-,';

Related

Code igniter - 404 not found, routes issue, ssh server

So first off, I am pretty familiar with codeigniter I've used it for multiple occasions. Right now I have a project too do for school and I installed codeigniter on the server but I am getting routing issues I believe.
So additional info about the server which is different from the normal environment I work with, the server uses SSH and it is very weirdly protected in my opinion. You also need a username and password to view the URL in the first place. (I think it's weird)
If this helps the url is:
https://clipper.encs.concordia.ca/~pyc353_2/
and credentials are (username: pyc353_2, password: FMaqRb)
Now I am able to see any page that I set as my 'default_controller' in the routes, but the problem is trying to go to any other page. Right now I'm trying to access the register controller and I just get 404'd (while it works if I set it as default)
I will link all the code I think may be relevant to the error, hopefully it's not server settings since I have no control over any change.
config.php
$config['base_url'] = 'https://clipper.encs.concordia.ca/~pyc353_2/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
routes.php
$route['default_controller'] = "test";
.htaccess (there may be better code for doing this but I used it in the past no problem and the route doesn't work even if I remove htaccess and add back index.php to 'index_page')
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>
So I tried accessing my pagedifferent variations in the url such as: (stackoverflow won't let me post more than 2 physical links)
clipper.encs.concordia.ca/~pyc353_2/register
clipper.encs.concordia.ca/~pyc353_2/index.php/register
neither work although with /index.php/ the error message is: "No input file specified."
So I hope my explanations are clear enough, it's hard to explain something I don't understand the source problem. If you need any additional info feel free to ask. I really need to solve this to proceed at all for my project.
EDIT
I don't know if this is relevant but the 404 message is not even in the codeigniter style it just looks like a plain web 404
Also I am looking at the path on the server and this is the hierarchy: /www/groups/p/py_comp353_2 I don't know if that could affect anything also?
NEWER EDIT
Following what I found here: http://ellislab.com/codeigniter/user-guide/installation/troubleshooting.html
Changing index.php to index.php? (and removing htaccess) actually did make the routing work. Now I am happy enough with this and I can continue working, but being that it's an ugly solve would anyone know how to keep the routing working AND remove the index.php? from my URI?
It appears that your htaccess is not working.
To confirm, create a new PHP file and write this line:
echo phpinfo();
On that page try to search for "mod_rewrite", if it is enabled, you will see it under "Loaded Modules"
It is probable, it is not enabled.
Try this on your server:
a2enmod enable
Then restart the apache server.
For restarting on debian, this should work:
service apache2 restart
For CentOS, this should work:
apachectl restart
That always does not solve the problem.
Even then, try your CI installation in the normal mode after that. (With everything in normal mode: htaccess as before, and no index.php in the URL)
If it does not work, you may need to alter the apache config file httpd.conf
Try to search for this line:
#LoadModule rewrite_module modules/mod_rewrite.so
Uncomment it by removing the # sign
Restart Apache Server.
Test it now, again.
There could still be other things that you could do to enable mod_rewrite.

CodeIgniter giving a 404 not found on public server only

Description
I have a site "searchnwork.com". It uses CodeIgniter. Every page except the home page loads fine.
If you go to searchnwork.com, it shows the CI 404 error page.
If you go to searchnwork.com/index.php/users, it shows the UserSignUpController page, which is good.
If I set the $route['404_override'] = 'UserSignUpController', I still get a 404.
Everything works fine on my local server.
Question
Why am I getting a 404 for searchnwork.com despite the override?
Why am I getting a 404 for searchnwork.com in the first place instead of my default controller?
Code
$route['users'] = "UserSignUpController"; // This loads fine.
$route['default_controller'] = "UserSignUpController"; // This gives a 404...
$route['404_override'] = 'UserSignUpController'; // This doesn't redirect...
Case sensitive file names.
On MAMP it doesn't seem to care about capitalization. When I uploaded to an actual linux server, CapitalizedFileNames started to fail, since it only searchs for lowercasefilenames. I guess you should use underscores.
Weird that it only fails for index.php.
You need to install a .htaccess on the server root
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Also make sure your /application/config/config.php is set up properly (these can by left blank and should still work properly)
$config['base_url'] = '';
$config['index_page'] = '';

ModRewrite .htaccess / SEO URLs syntax

I am trying to re-use some .htaccess code on a new site/server and it doesn't work correctly. I'm not an expert with URL rewriting so would appreciate it if anyone can see if my syntax is incorrect or if there is something else I need to check server side.
I am using the following code:
Options +FollowSymLinks
RewriteEngine on
# News Pages
RewriteRule ^news/$ /news.php
RewriteRule ^news/(.*?)/$ /news.php?article=$1
It works for the 1st level, /news/ but /news/article-1/ just loads the /news/ (news.php) overview page. /news.php?article=article-1 works correctly.
Server is running Apache 2.2.9 and PHP is in CGI mode.
Try it such way:
RewriteRule ^news/(.*?)/?$ /news.php?article=$1 [L]
RewriteRule ^news/?$ /news.php [L]
[L] in the end of instruction stops server cheacking of other instructions, if current one match.
So you write more specific ahead of more general.
If your rules work correctly being the only one in the .htaccess, then such organisation of them can help.
/? - this means that / at the end can absent or present

strange behavior SSL acts when rewriting url

I believe there is something weird when I have rewritten my urls. My website links are forced to use SSL and when I click on any, the browser shows OK for SSL on Chrome (green color on https), safe site or identified certificate on Firefox, and the same OK working SSL on other browsers.
Now the problem starts whenever I rewrite the url using mod_rewrite and shorten the link a red sign shows up on Chrome, not identified on FireFox, and the same issue on other browsers.
I guess the problem is somewhere in the rewrite code or something is missing has to be added!
Update #1
RewriteCond %{REQUEST_URI} ^(/pro)
RewriteRule ^(.*)$ /foo/loop/sps/click/$1 [L]
RewriteCond %{REQUEST_URI} ^/foo/loop/sps/click
RewriteRule foo/loop/sps/click/(pro)(/(.*))?$ $1$2 [R,L]
and of course adding php handler : DirectoryIndex index.php
Update #2
The error I get is the red sign in Chrome for example. That happens when I enter a url shortened using rewrite url mod_rewrite.
SSL issues can be complex and depend on several different variables. The most likely case is that when you rewrite the URL's, you are changing the host name. Let's say you rewrite "https://www.test.com/whatever" to "https://test.com/w". In this case, if the SSL certificate was assigned to "www.test.com", you will get a red sign saying the certificate is valid but does not match the URL.
If that does not help, we would need more details on the SSL certificate, the exact SSL error you're getting, and examples of rewritten URL's.

mod_rewrite rule not working

I have the following rules in my htaccess:
RewriteRule ^([^/.]+)/?$ list.php?categoryShortForm=$1&locationShortForm=world [QSA]
RewriteRule ^([^/.]+)/([^/.]+)/?$ list.php?categoryShortForm=$1&locationShortForm=$2 [QSA]
RewriteRule ^([^/.]+)/([^/.]+)/[^/.]*-p([0-9]+)/?$ view.php?categoryShortForm=$1&locationShortForm=$2&postingId=$3 [QSA]
In my localhost (windows, xampp), it all works fine.
In my real server (linux, apache) the first 2 rules work fine, but not there 3rd one.
For example:
/plastic-surgery/california-usa/ works fine, but
/plastic-surgery/los-angeles-california-usa/test-1-p1 gives me a 404
Any idea??
Check to make sure that you can browse directly to the target URLs. If mod_rewrite is rewriting onto something that doesn't exist, you'll get that 404. It might help to ratchet up mod_rewrite's log level to a high value, so you can see what it's rewriting to.
I am a little unclear on how your working URL is supposed to actually work. All three of your patterns start with "one or more non-slash, non-period characters" ([^/.]+), but URLs going into the pattern matching start with slashes: "/plastic-surgery/california-usa/".
Have you turned on mod_rewrite logging and checked out what mod_rewrite is actually doing?
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9

Resources