.htaccess file
- Single Page
Posted 09 July 2012 - 07:19 AM
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.
Thanks!
Posted 09 July 2012 - 23:17 PM
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:
http://stackoverflow.com/questions/11057519/codeigniter-and-mod-rewrite-with-multiple-applications/11057652#11057652
Let me know if you have any questions.
Cheers!
Posted 10 July 2012 - 06:47 AM
# 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 [attachment=218:htaccess.txt] (don't forget to rename it to .htaccess)
Posted 10 July 2012 - 16:33 PM
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
</IfModule>
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://[b]www[/b].site.com to http://site.com and the other one does vice versa: from http://site.com to http://[b]www[/b].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?
Posted 11 July 2012 - 06:40 AM
I'm also using the boilerplate .htaccess it great and I think it has the most needed things
Posted 11 July 2012 - 14:09 PM
Your .htaccess is very clean and straight forward. I will give it a try.
Cheers.
Posted 30 August 2016 - 13:14 PM
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-8Also 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 htaccess.txt (don't forget to rename it to .htaccess)
This doesn't work for me on CI 3.x
my CI config:
$config['base_url'] = 'http://mypc.local';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
it works for http://mypc.local/home
it works for http://mypc.local/index.php/home
it works for other websites which don't utilize GC
it works for http://mypc.local/index.php/examples (GC)
BUT not for http://mypc.local/examples (GC)
it shows:
Service unavailable!
anyone can help?