Jump to content

.htaccess file

  • Please log in to reply
5 replies to this topic

#1 noskov


    grocery CRUD Guru

  • Advanced Member
  • PipPipPip
  • 175 posts
  • LocationKiev

Posted 09 July 2012 - 07:19 AM

Hi everybody!

To tell the truth I don't know much about the .htaccess file. At the beginning I had in my .htaccess a few lines that we can find in the CodeIgniter user guide. Then I started to use .htaccess file that is suggested by HTML5 Boilerplate.

So I wonder what options can we use to make it better in our projects with CodeIgniter and Grocery CRUD? And it is really interesting for me to hear your opinion about .htaccess file.


#2 fdias


    grocery CRUD Addict

  • Members
  • PipPipPip
  • 93 posts

Posted 09 July 2012 - 11:17 PM

Dear Noskov,

I've used .htaccess files mostly for URL rewrite and basic folder protection.
In CI I've used a great .htaccess file that I shared on stackoverflow and will share with you as well.

Find the file on the link below:


Let me know if you have any questions.


#3 web-johnny


    grocery CRUD Author

  • Administrators
  • 935 posts
  • LocationLondon

Posted 10 July 2012 - 06:47 AM

I always use a simple one like for 4 years and it works everywhere:

# Turn on URL rewriting
RewriteEngine On

RewriteBase /

# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs|templates/(.+)/(.+)/template\.php)

# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]

# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|opensearch\.xml|favicon\.ico|assets|forums)

# No rewriting
RewriteRule ^(.*)$ - [PT,L]

# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]

# Use UTF-8 encoding for anything served text/plain or text/html
AddDefaultCharset utf-8

Also an other useful thing is to redirect the base to www with this simple lines of code:
RewriteCond %{HTTP_HOST} ^grocerycrud.com
RewriteCond %{HTTPS} !=on
RewriteRule (.*) http://www.grocerycrud.com/$1 [R=301,L]

You can also download the file Attached File  htaccess.txt   855bytes   228 downloads (don't forget to rename it to .htaccess)
Posted Image

#4 noskov


    grocery CRUD Guru

  • Advanced Member
  • PipPipPip
  • 175 posts
  • LocationKiev

Posted 10 July 2012 - 04:33 PM

Hi again and thank you for your replies, my friends!

1) ./application/ & ./system/ protection. I have often seen that developers try to protect these folders as much as possible. But in the Boilerplate .htaccess I found next lines that protect every folder in the project from browsing if it has't index.html file. What do you think about this?

# "-Indexes" will have Apache block users from browsing folders without a default document
# Usually you should leave this activated, because you shouldn't allow everybody to surf through
# every folder on your server (which includes rather private places like CMS system folders).
<IfModule mod_autoindex.c>
  Options -Indexes

2) Flag "passthrough|PT". Hm, I've never seen this before. As I learn today ;), this flag is used when we want to "mix" some directives from different Apache modules. But there is only RewriteRule in your code, web-johnny. Why do you use [PT]? Sorry, if I ask stupid questions.

3) About base redirect. In the Boilerplate .htaccess file there are two variants. The first one redirects from http://www.site.com to http://site.com and the other one does vice versa: from http://site.com to http://www.site.com. I use the first option without "www", it seems to me that users hardly ever type "www" in the browser, so I follow them. What do you think about "www" in the urls?

#5 xxaxxo


    grocery CRUD Expert

  • Members
  • PipPipPip
  • 71 posts
  • LocationBulgaria

Posted 11 July 2012 - 06:40 AM

+1 for the plain url without www - some people dont understand it and think that you are always supposed to use it and other just know ;)
I'm also using the boilerplate .htaccess it great and I think it has the most needed things

#6 fdias


    grocery CRUD Addict

  • Members
  • PipPipPip
  • 93 posts

Posted 11 July 2012 - 02:09 PM


Your .htaccess is very clean and straight forward. I will give it a try.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users