Part of the EllisLab Network
   
 
Quick htaccess/redirect question
Posted: 17 July 2008 03:00 PM   [ Ignore ]  
Summer Student
Total Posts:  7
Joined  04-15-2007

Got the initial htaccess code from the wiki working great. My CI site currently resides in a subdirectory on the main site - my .htaccess file lives in that directory. so:

www.mysite.com/subdirectory/index.php/home/category/clothing

becomes

www.mysite.com/subdirectory/home/category/clothing

however, I want the above url to become this:

www.mysite.com/subdirectory/clothing.php

basically take the controller “home” and “category” out of the url.

i also want the ability to add another uri and maintain the flow, for example:

www.mysite.com/subdirectory/home/category/clothing/mens

becomes

www.mysite.com/subdirectory/clothing/mens.php

This is my .htaccess file right now (standard from the wiki i think):

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /onlinecatalogs/

  #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]

  #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>

Any help would be greatly appreciated! grin

Profile
 
 
Posted: 07 August 2008 08:22 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  7
Joined  04-15-2007

Still having problems. Anyone a htaccess guru?

Profile
 
 
Posted: 07 August 2008 11:05 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  197
Joined  11-25-2007
<IfModule mod_rewrite.c
RewriteEngine On 
RewriteBase 
/onlinecatalogs

#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] 

#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} !-
RewriteCond 
%{REQUEST_FILENAME} !-
RewriteRule 
^(.*)$ index.php/home/catagory/$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

Try that.

Profile
 
 
Posted: 07 August 2008 11:13 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
RankRank
Total Posts:  140
Joined  04-24-2007

There’s an alternative to using .htaccess for this. You could add a url suffix in config.php ($config[‘url_suffix’]) and then use routes to remove the “home” from the url.

 Signature 

CI Bookmarks

Profile
 
 
Posted: 07 August 2008 11:34 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  7
Joined  04-15-2007

I believe it works! Thanks!

Actually i’m noticing the changes between this and the oringial .htaccess file that I was trying, and the other file i was playing with earlier today. I should be able to make adjustments, learning this as I good along. So i’m walking away an educated coder on this. grin

Profile
 
 
Posted: 18 December 2008 09:29 PM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  1
Joined  11-08-2007
SpooF - 08 August 2008 03:05 AM
<IfModule mod_rewrite.c
RewriteEngine On 
RewriteBase 
/onlinecatalogs

#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] 

#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} !-
RewriteCond 
%{REQUEST_FILENAME} !-
RewriteRule 
^(.*)$ index.php/home/catagory/$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

Try that.

Hi I try to use your configuration to create a site into my localhost with this configuration:

The index.php file it’s in /mysite/system/application/views/index.php
why? because with this way users cannot enter to other folders

the rules of the .httaccess are:

RewriteEngine On
RewriteBase 
/mysite/


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d

RewriteCond 
$!^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ system/application/views/index.php/$1 [L] 

So, my problem is the url like http://localhost/mysite/css/common/reset.css for some reason I can’t read the file reset.css

Can you help me??

Thanks!!!

Profile
 
 
Posted: 19 July 2010 12:01 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  139
Joined  03-18-2008
Eaven - 19 December 2008 02:29 AM

Hi I try to use your configuration to create a site into my localhost with this configuration:

The index.php file it’s in /mysite/system/application/views/index.php
why? because with this way users cannot enter to other folders

the rules of the .httaccess are:

RewriteEngine On
RewriteBase 
/mysite/


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d

RewriteCond 
$!^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ system/application/views/index.php/$1 [L] 

So, my problem is the url like http://localhost/mysite/css/common/reset.css for some reason I can’t read the file reset.css

Can you help me??

Thanks!!!

Eaven,

Your problem is that

system/application/views/index.php 

is not the location of the root of your site.  The root of the CodeIgniter site is actually the index.php file on the same level as the system folder.  So, it would look like this:

localhost
    
/mysite
        
/common
            
/css
        
/index.php
        
/system
            
/application 

Hope this helps.

Note: I just noticed how old this post is. Ha!

Profile