Code Igniter - URL Rewrite - .htaccess

Hey, i'm trying to get a project to work, but i am having trouble with the rewrite module.
I'm running Wamp over Windows XP. I changed httpd.conf to change the root of localhost to:
DocumentRoot "C:/wamp/www/project/docroot/"
I have htaccess
RewriteEngine On
RewriteBase /
my Apache has the rewrite module Activated.
my base_url() in config.php is 'http://localhost/'
in routes.php i have:
$route['default_controller'] = "home";
$route['our-recipes'] = "recipes";
and more pairs
when i point the browser to http://localhost/ i get the homepage of my site, but when i click on any internal link like to 'our-recipes' it loads but i get the same homepage, with the new url on the location bar. if i try to access 'http://localhost/recipes' i get the same result.
this is my folder structure:
Can anyone please solve this for me??

Give this a shot (taken from the wiki)
<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>

Related

Codeigniter - URL rewrite

I have a url: http://localhost/mypay/admin/company/edit/profile
Is it possible to make it more like a native fashion way:
http://localhost/mypay/admin/company/?edit=profile
I currently have a .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mypay/
#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've seen it to other sites and wanted it to be used in mine for easy readability. Thank you.
james
If you want to enable the $_GET array, in config/config.php set these values:
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = TRUE;
In your controller you can then do:
$edit = $this->input->get('edit');

Server ignoring subdirectory htaccess file, going straight to root htaccess

I have an application that utilizes Codeigniter and SLIR (Smart Lencioni Image Resizer https://github.com/lencioni/SLIR). SLIR allows you to resize images using an intuitive URI structure. For example:
<img src="/slir/w100-h100/path/to/image.jpg"/>
This would resize the image to fit 100px * 100px. For whatever reason when I try to view a resized image, (eg. http://a2op03.com/slir/w300-h90/images/content/franchise-opportunities-badge.png) I am getting a 404 error generated by Codeigniter. I have verified the following:
http://a2op03.com/images/content/franchise-opportunities-badge.png does exist.
According to the host mod_rewrite is setup properly and working.
GD Library (for SLIR) is setup and enabled
According to SLIR, everything is setup properly (http://a2op03.com/slir/install/)
The Codeigniter [root] htaccess file looks like this:
<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>
and the htaccess file in /slir/ looks like this:
# Prevent other scripts from interfering with SLIR
php_value auto_prepend_file none
php_value auto_append_file none
# Pretty URLs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=40]
RewriteRule . index.php [L]
</IfModule>
# Prevent viewing of the error log file in its default location
<Files slir-error-log>
Order Deny,Allow
Deny from All
</Files>
My initial suspicion was that mod_rewrite.c was not setup properly and therefore was not being processed by the SLIR htaccess and falling back on the root htaccess which is sending it to a 404. I'm hosting on a managed VPS via servint.net and have WHM with full access to the server. The host claims that mod_rerwrite should be working fine. I have this working flawlessly on another server, but I can't figure out why it's not working here. Any helps is appreciated!
I figured it out! I just needed to add
RewriteBase /slir/
After
RewriteEngine On
In SLIR's htaccess file!

Getting rid of index in URL when using CodeIgniter and HTTPS

I've been working on a codeigniter application. When I first started developing it I used the following url structure:
http://somewebsite.com/application/login/
I changed the site to run over https
https://www.somewebsite.com/application/login/
The problem is any calls to the server only work like this.
https://www.somewebsite.com/application/index.php/login/
I want to get rid of the index.php. Any thoughts?
You need to have you .htaccess rewrite SSL properly. This is an .htaccess I use that works - although it FORCES SSL. Not sure if you want to do that:
<IfModule mod_rewrite.c>
RewriteEngine On
#Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R,L]
#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>
check and edit the application/config/config.php.
in that change the following line
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
just remove index.php and then it should work lust fine...

remove index.php of codeigniter subdomains

this is my directory:
-root
-CI
-application
-system
-sub-domain1 (codeigniter )
-application
-sub-domain2 (codeigniter )
-application
-www
-folder1
-folder2
.....
-folder10
-sub-domain1
-index.php (used for codeigniter)
-sub-domain2
-index.php (used for codeigniter)
-file1.php
-file2.php
-file3.php
.....
-file10.php
-index.php (used for codeigniter)
- .htaccess
in my application/config/config.php is:
$config['index_page'] = "";
I didn't have the sub-domain1 and sub-domain2 and I wanted to apply them now. I am using same system for all CIs. I used the following htaccess file and it works perfect.
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>
now when I add sub-domain1 and sub-domain2 I have problem with index.php. for main CI index.php is gone but for sub-domains I don't know how i can do that.
www.mydomain.com/folder1/... ok
www.mydomain.com/controler/function ok
www.sub-domain1.mydomain.com/index.php/controler/function ok
www.sub-domain1.mydomain.com/controler/function NOT ok
please help me.
thanks
You should be able to share the system directory across all of your CI installations, providing a central place for upgrades, and using less disk space.
Take a look in application/config/config.php
and the line: $config['index_page'] = "index.php";
should look like: $config['index_page'] = "";

htaccess file removing index.php in CodeIgniter - 500 Internal Server Error

Wonder if anyone can help with this .htaccess problem - I've had it working for months and now it's stopped working after some stupid delete errors on my part, but now have no idea how to sort this problem.
If anyone could help it'd be much appreciated!
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /MMSFL/
    #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> 
A couple of changes made here try it out and see if this works:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /MMSFL/
#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,QSA]
</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>
Also make sure your directory is correct. (In RewriteBase)

Resources