I'm setting up Haughin's Twitter OAuth Library for CodeIgniter, and one requirement is to change the uri_protocol in config.php to PATH_INFO, which seems to be breaking my app in the way that all requests load the home controller (ex. Navigating to http://dev.myapp.com/login would normally take my to the Login controller, but it's just showing the default controller.)
Any ideas what would be causing this, or maybe an Apache2 configuration that's messed up?
Its to do with URL rewrites. Check your .htaccess files to see if you have the correct rewrite rules. Here is something that works for me when using PATH_INFO.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
The above should work for you without any modification. If you're hosting in a folder lets say like http://myserver.com/my_app/ then change /index.php to /my_app/index.php in both places.
Related
I have a little problem with codeigniter and the default controller behavior.
My CI resides in a subdir on the development environment at localhost/web/new_info and the same path for production like 192.168.30.108/web/new_info.
Always when calling the url like
localhost/web/new_info/welcome
the page takes me to the server root, e.g. localhost/.
But I can call the "welcome" controller via:
localhost/web/new_info/
localhost/web/new_info/index.php/welcome
and I can call welcome's methods as well like
localhost/web/new_info/welcome/logout
There is another subdir in my controllers called settings and contains another welcome.php intself. I can access this controller directly without problems and the page stays there
localhost/web/new_info/settings/welcome
There is .htaccess and mod_rewrite set up according to
http://www.farinspace.com/codeigniter-htaccess-file/.
.htaccess
SetEnvIf Host 192.168.30.108$ CI_ENV=production
SetEnvIf Host localhost$ CI_ENV=development
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/new_info/
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
in config/development/config.php I have
...
$config['base_url'] = 'http://localhost/web/new_info/';
$config['index_page'] = '';
...
and generic routes
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Xampp and the real server running apache2 act the same way. Even after completely disabling mod_rewrite and calling the welcome controller redirects to server root.
Currently I am using CI 3.0.3 and tested with the latest 3.0.6 as well with the same behavior.
What I want is to call localhost/web/new_info/welcome and stay there..
Thank you!
Ok, found out by myself.. dumb copy paste of .htaccess.
Namely the line
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
has to be
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ /web/new_info/ [L,R=301]
in my case. The author of the htaccess file didn't mention it on his page.
But changing the htaccess file only did not help. I had to completely restart my session, otherwise changes were not applied. It's a bit unusual for me, I thought changes in this file were instant.
Nevertheless, it's fine now.
I just moved old site of my client to some test server.
The site is on PyroCMS.
I've changed database settings in aplication/config/database.php and changed base_url in aplication/config/config.php to my test site URL.
Unfortunatly site is giving me 500 error and I don't have any error logs to see what else is to change.
Where I have to do changes to site run?
My .htaccess looks like this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /wherever/pyro/is
# Keep people out of codeigniter directory and Git/Mercurial data
RedirectMatch 403 ^/(application\/cache|codeigniter|\.git|\.hg).*$
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I use PyroCMS for almost all my clients and the same issue is in the default .htaccess file.
Try to remove:
Options +FollowSymLinks
And try to add:
Options +symlinksifownermatch -Indexes
Options -MultiViews
Many hosting disable +FollowSymLinks for security reason.
Make sure to set 775 permission to:
system/cms/cache
system/cms/logs
addons
uploads
assets
Also make sure to set your env to PYRO_DEVELOPMENT to see all the errors in this debug phase.
I've made a one-page design and would like to route somesite.com/contact to somesite.com/index.php#contact. I'm using a href id's and div id's. But none of the routes i make seems to be working.
examples:
$route['contact'] = "pagescontroller/index#contact";
$route['contact'] = "base_url('#contact')";
How could i make this work?
Thanks in advance!
You will need to use the # so the browser knows you are going to a part of the page. If you really want to remove it, you could use it as a parameter for the controllermethod you use to display your page and use javascript to go the that specific id on your page.
I would not do that since you will reload your page every time you click on a link. (Unless you use javascript to suppress that as well and go to the relevant ID.)
You could however use mod_rewrite in .htaccess for removing the index.php from your url. So your url's will look like http://example.com/#about
My .htaccess-file for codeigniter is this:
<IfModule mod_rewrite.c>
RewriteEngine On
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#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>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I am facing a different problem in codeigniter.
When I try to access the videos page in my site, it will redirect to 404.shtml page. But cvideos.php file exists in my controllers folder.
If I access like this http://domain-name/videos , then it will be redirected like this
//domain-name/500.shtml
And If I access the same page like this //domain-name/videos/myvideos, then then it will be redirected like this
//domain-name/404.shtml
Also, If I change the controller name from videos to some other name like videoss it works fine. Can anyone tell wats the issue.
I used this line in my .htaccess also just for testing. But no use.
RewriteRule ^videos/$ index.php/videoss/ [L]
Your controller needs to be the same name as the class it contains.
hence -
<?php
controller Videos extends Controller {
/* bla */
}
?>
should be saved as:
videos.php in the "controllers" directory.
Nothing else will work.
also your rewrite rule has two "s"'s, but that might be intentional.
and it looks like what you are trying to do with .htaccess can be achieved with CI's routing
Edit: .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#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>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
please note I did not create this - it was found by scouring the CI forums. It's a rather thorough htaccess however.
Don't forget to set the value of "index.php" to "" in your config.
base_url is case sensitive
localhost/site/controller = c:...\site
localhost/SITE/controller = c:...\SITE
make sure you are not missing .htaccess file in your root directory. Or check for its accuracy. Make sure uri_protocol and base_url are set correctly in config.php.
for sample, i am copying my .htaccess file here
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your_dir
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I used this to get rid of index.php in url.
I had a similar problem when transferring a CI site from WAMPP to a LAMPP that someone else had made. It would seem that WAMPP was configured to be case-insensitive, as when I converted all my controller/model/view file names and all php strings containing controller/model/view names to lowercase it worked perfectly.
I'm pretty new to mod-rewrites, and I'm having trouble getting this right:
I'd like http://myurl.com/special and http://www.myurl.com/special to both redirect to http://myurl/index.php/special without changing the url for the visitor in their browser.
currently, my .htaccess looks like this, to remove www from URLs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.myurl.com [NC]
RewriteRule ^(.*)$ http://myurl.com/$1 [L,R=301]
</IfModule>
I tried a bunch of different things to redirect the special URL, but nothing has worked for me so far, each with a different undesirable result. Please let me know if you have an idea about what I can add here!
I tried this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^special$ /index.php/special$1 [NC]
RewriteCond %{HTTP_HOST} ^www.myurl.com [NC]
RewriteRule ^(.*)$ http://myurl.com/$1 [R=301]
</IfModule>
That makes http://myurl.com/special redirect to the default controller, and makes http://www.myurl.com/special redirect to http://myurl.com/index.php/special AND changes the url in the browser. Neither of those is quite right, although the second is closer to what I need.
oh no you don't need htaccess to do that just use CI's routes. Here first change your HTACESS to this:
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
This one is way way better and you never have to change it for anything not for img folders or anything just leave it pure. now for your issue.
open routes php in the Application->config folder.
Now in CI all files route through index.php by default so i am assuming you mean your default controller anyway to route "controllers" like in your case special back to the main site just do this:
if your default controller is still "welcome" as it is downloaded you would write a route like this:
$route['special/(:any)'] = "welcome";
your url will not change and everything will be perfect
BUT DONT STOP READING YET, JUST TO MAKE SURE.
this is what your routes would look like after your done:
//these two are for CI
$route['default_controller'] = "welcome";
$route['scaffolding_trigger'] = "";
//this is your route sending all and any traffic for special
//no matter how many levels it will always go to welcome->index.
$route['special/(:any)'] = "welcome";
//if you want to use sub-pages or other functions within your welcome controller
//i.e. welcome->signup. then just send the route information to the controller like this:
$route['special/(:any)'] = "welcome/$1";
The routing class in php is very powerful and this is just a piece here for more detailed info on routing see this page:
CodeIgniter User Guide -> URI Routing
Really hope i haven't confused you more. Good Luck
Assuming www.myurl.com and myurl.com are both set-up as ServerAliases in your VirutalHost, then something as simple as...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>