Part of the EllisLab Network
This thread is a discussion for the wiki article: Dreamhost .htaccess
   
1 of 2
1
Dreamhost .htaccess
Posted: 01 October 2008 02:27 PM   [ Ignore ]  
Summer Student
Total Posts:  2
Joined  10-01-2008

I found this article here on CI’s website but can’t seem to find a tutorial for setting up htaccess (to remove the index.php specifically) with a Hostgator account. I’m not sure if that’s what I need but I do know that the same htaccess file that works locally doesn’t work on my Hostgator server. Here’s the htaccess code:

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

    
#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

Thanks in advance!

Profile
 
 
Posted: 01 October 2008 05:27 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  2
Joined  10-01-2008

Finally it’s working. I tried all the htaccess code I could find, set $config[‘index_page’] = ‘’; in ci/application/config/config.php, and even had it working locally, but could not, for the life of me, get it to work live. Can’t remember where I saw this but someone suggested setting…

$config['uri_protocol']    "REQUEST_URI"

...in ci/application/config/config.php.

That seems to work (remove the index.php with htaccess that is) with the htaccess in my previous post.

Profile
 
 
Posted: 10 June 2009 11:34 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  3
Joined  05-09-2009

Solution 1 worked for me right away. In config.php, my index_page is set to “” and my uri_protocol is set to the default “AUTO”. That’s all.

Profile
 
 
Posted: 19 June 2009 12:00 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  8
Joined  06-19-2009

Thanks a lot! It solved my problem too on Hostgator.

Have a nice day.

Profile
 
 
Posted: 25 June 2009 04:39 AM   [ Ignore ]   [ # 4 ]  
Lab Technician
RankRankRankRank
Total Posts:  1264
Joined  04-19-2008
answerervice45 - 25 June 2009 08:37 AM

Finally it’s working. I tried all the htaccess code I could find, set $config[‘index_page’] = ‘’; in ci/application/config/config.php, and even had it working locally, but could not, for the life of me, get it to work live. Can’t remember where I saw this but someone suggested setting…

Regards


Peter

Answering Service

Medical Answering Service

I almost believed it was a genuine post (he copied it from above).

 Signature 

PinoyTech - Web Development Blog

Profile
 
 
Posted: 28 August 2009 05:52 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  4
Joined  08-28-2009

I had before also problem’s with .htaccess and Hostgator. Something with modrewrite they said, not sure.

But know everything is fine again.

Profile
 
 
Posted: 04 February 2010 06:31 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Avatar
Total Posts:  1
Joined  01-28-2010

for anyone setting up clean urls on a dreamhost account:

I was continually getting errors from my dreamhost server, it turns out that this line in the .htaccess file:

RewriteRule ^(.*)$ index.php/$1 [L]

Should have a ‘?’ appended to the ‘index.php’ so it ‘forces the server to treat everything after it as a query string’ according to dreamhost wiki - http://wiki.dreamhost.com/Mod_rewrite

RewriteRule ^(.*)$ index.php?/$1 [L]

wish me luck this is my first stab at CI wink

Profile
 
 
Posted: 26 March 2010 08:32 AM   [ Ignore ]   [ # 7 ]  
Summer Student
Total Posts:  10
Joined  03-03-2008

Thanks mrwilljackson!

I’m working on a project with a client on dreamhost and couldn’t get the .htaccess set up right.  That simple ? worked!

Thanks for posting, that made my day.

Profile
 
 
Posted: 26 March 2010 02:16 PM   [ Ignore ]   [ # 8 ]  
Summer Student
Avatar
Total Posts:  6
Joined  03-25-2010

My dreamhost .htaccess working 100%.
In config.php, my index_page is set to “” and my uri_protocol is set to the default “AUTO”.

<IfModule mod_rewrite.c>
    
Options +MultiViews +FollowSymLinks
    
    DirectoryIndex index
.php index.html
    RewriteEngine on

    RewriteRule modules
/(.+)/controllers/(.+)\.php$ /index.php?/$1/$2 [L,R=301]
    RewriteRule controllers
/(.+)\.php$ /index.php?/$1 [L,R=301]
    
    RewriteCond 
%{REQUEST_FILENAME} !-f
    RewriteCond 
%{REQUEST_FILENAME} !-d
    RewriteRule 
^(.*)$ index.php?/$1 [L]
</IfModule

That’s all.

Regards…. cool smile

Profile
 
 
Posted: 09 April 2010 05:51 PM   [ Ignore ]   [ # 9 ]  
Summer Student
Avatar
Total Posts:  7
Joined  05-02-2007

I struggled with this for about an hour, trying multiple configurations of .htaccess files.

Ensure that when you are creating the .htaccess FILE (I used notepad++), that you REMOVE/CONVERT the file to NOT have a BOM at the beginning.

I can’t be the only one that was banging my head on a wall over this…

 Signature 
documentation is like sex//when it's good, it's really good, 
//and when it's bad, it's better than nothing. 

“Web design is the creation of digital environments that facilitate and encourage human activity; reflect or adapt to individual voices and content; and change gracefully over time while always retaining their identity.”
- Jeffrey Zeldman

Profile
 
 
Posted: 22 April 2010 04:08 PM   [ Ignore ]   [ # 10 ]  
Summer Student
Total Posts:  1
Joined  04-21-2010

I always like to know some important things about Dreamhost htaccess. So i adhere to this site for collecting some important and useful topic for post and sharing with some of my friends. I like this article. its so nice.

Profile
 
 
Posted: 06 August 2010 03:58 AM   [ Ignore ]   [ # 11 ]  
Summer Student
Total Posts:  1
Joined  08-04-2010
Miguel Ramos - 26 March 2010 06:16 PM

My dreamhost .htaccess working 100%.
In config.php, my index_page is set to “” and my uri_protocol is set to the default “AUTO”.

<IfModule mod_rewrite.c>
    
Options +MultiViews +FollowSymLinks
    
    DirectoryIndex index
.php index.html
    RewriteEngine on

    RewriteRule modules
/(.+)/controllers/(.+)\.php$ /index.php?/$1/$2 [L,R=301]
    RewriteRule controllers
/(.+)\.php$ /index.php?/$1 [L,R=301]
    
    RewriteCond 
%{REQUEST_FILENAME} !-f
    RewriteCond 
%{REQUEST_FILENAME} !-d
    RewriteRule 
^(.*)$ index.php?/$1 [L]
</IfModule

That’s all.

Regards…. cool smile

Thanks so much Miguel Ramos. It’s really worked.

Profile
 
 
Posted: 23 August 2010 08:24 AM   [ Ignore ]   [ # 12 ]  
Summer Student
Total Posts:  26
Joined  08-07-2009

I’m on dreamhost and recently had my web app migrated to the new servers. And I found my way here because my .htaccess got broken.

I’ve experimented and tried the samples given above and they all work fine. The only problem is, query strings no longer work. e.g. http://example.com/controller/function?api_token=1234567

I need the query string to work because I’m using Elliot Haughin’s Twitter CI library ( http://www.haughin.com/code/twitter/ ). Twitter’s auth server will return the token keys via query string.

Is there any workaround or .htaccess trick to get it to work?

My current .htaccess content is:

RewriteEngine on
RewriteCond 
$!^(index\.php|images|robots\.txt|style\.css|scripts|favicon\.ico)
RewriteRule ^(.*)$ /index.php?/$1 [L] 
Profile
 
 
Posted: 25 August 2010 03:10 AM   [ Ignore ]   [ # 13 ]  
Summer Student
Total Posts:  1
Joined  08-25-2010

Thanks a lot, it’s worked!

Profile
 
 
Posted: 26 August 2010 07:46 AM   [ Ignore ]   [ # 14 ]  
Summer Student
Total Posts:  26
Joined  08-07-2009
wyred - 23 August 2010 12:24 PM

I’m on dreamhost and recently had my web app migrated to the new servers. And I found my way here because my .htaccess got broken.

I’ve experimented and tried the samples given above and they all work fine. The only problem is, query strings no longer work. e.g. http://example.com/controller/function?api_token=1234567

I need the query string to work because I’m using Elliot Haughin’s Twitter CI library ( http://www.haughin.com/code/twitter/ ). Twitter’s auth server will return the token keys via query string.

Is there any workaround or .htaccess trick to get it to work?

My current .htaccess content is:

RewriteEngine on
RewriteCond 
$!^(index\.php|images|robots\.txt|style\.css|scripts|favicon\.ico)
RewriteRule ^(.*)$ /index.php?/$1 [L] 

In case anyone has the same problem as me, I’ve thought of another solution which is to use $_SERVER[‘REQUEST_URI’] to get the URL together with the query string that was with it.

As long as we can get the api key from the URL, it’s only a matter of using a few explode()s (or any other better way if you have) to narrow down to the actual value.

Profile
 
 
Posted: 22 October 2010 10:33 PM   [ Ignore ]   [ # 15 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1090
Joined  08-06-2006

i was having problems all day with what seemed to be 404 misfirings. i got to know the Router.php pretty well through it all, so it wasn’t a complete waste of a day…

anyway, i just finished chatting with a dreamhost tech support person who told me that a user account i have with them was hitting process memory resource limits (all processes) and that was what was causing strange, seemingly htaccess-related problems. i was getting intermittent 404 errors from an htaccess file that should not have been called at all! and for a long time, i thought CI was to blame. silly me, all along CI was my friend and it was dreamhost with the haunted house.

apparently, the process killing robot that dreamhost uses will kill a web process in the middle and then for some reason, the (now zombie) apache actually tries to finish its job (doing its best to exit cleanly out of the unglamorous end to a subrequest is my best guess). it throws a 500 error into the main http log, but after doing so, it actually fires off the rewrite condition and rule that should never have been fired (using the standard file -f and directory -d htaccess file above) - and it doesn’t write a new log entry! a new (invisible man) request then triggers the index file in the last line of the htaccess file

beware the resource limits in dreamhost basic accounts! if you go over their limits, and you have htacess with mod_rewrite lines you will see strange things that are only fit for halloween night - invisible men, haunted 404s! undead processes! zombie apache! htaccess moving on its own! yikes!

hope this helps you avoid some hours of pain.

 Signature 

peeker email (imap/pop) | site_migrate | OOCalendar | PhotoBox2 | word_limiter

Profile
 
 
   
1 of 2
1
 
‹‹ Modular Extensions - HMVC      DataMapper ››