I have an application that works great when using the full url: sitename.com/index.php/foo/ but when I use HTaccess to remove the index.php it doesn't seem to work as expected. No matter which page I access I only see the home page. The htaccess file is doing something because without that line I get a 404 error.
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|file-manager-files|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
Thoughts?
On my test site everything works just fine. Is this a server setting that needs to be tweaked?
With Codeigniter you want something 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>
If that is not working, check to make sure $config['index_page'] = ''; and your .htaccess directives are set right:
<Directory "/some/absolute/path/htdocs">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
I've done hundreds of Codeigniter installs on many OS configs and have always been able to get this to work, but I have had some issues occasionally where I had to get creative to get the index.php to disappear.
The RewriteCond is wrong. In first argument you have to use what to check. In example the requested URI, the script file name and so on. On the above example it looks like you try to compare $1 (dolar and one) to the right part of the Rewrite Condition :?
Related
I have installed PHP, Mysql and Apache on windows server 2008 R2 as this link provided exactly.
It's working like a charm, but the problem is with my .htaccess to remove index.php.
My .htaccess file includes the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /HR/ #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 already enabled mod_rewrite in apache. but I'm getting 500 internal server error.
NOTE: when changing AllowOverRide All to None in Document root like here:
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
the 500 internal error disappears but the .htaccess does not work!!! then I should add the index.php for the link to work.
Note: when AllowIverRide All I get this error:
[Tue Feb 19 18:20:10.988018 2013] [core:alert] [pid 3940:tid 844]
[client 127.0.0.1:49513] C:/Apache24/htdocs/HR/.htaccess:
RewriteBase takes one argument, the base URL of the per-directory context
Any help will be Appreciated. TY.
Not to completely change your .htaccess entirely, but here is an example of the one I use that I never have any issues with. This is only the part in regards to modrewrite:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(templates|plugins)
RewriteRule ^(.*)$ index.php/$1 [L]
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!
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...
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)
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>