Welcome Guest, Not a member yet? Register   Sign In
Better super .htaccess file and tutorial coming your way.
#11

[eluser]simshaun[/eluser]
Do you think it would be possible to put this in the CodeIgniter docs after its been fully reviewed?

If not, I'll continue to look these threads up. Otherwise, great!


It may also be useful to make this note:
If you have the user_guide folder in your app (during development), you would need an .htaccess in that folder containing the following line:
Code:
DirectoryIndex index.html
#12

[eluser]Daniel Moore[/eluser]
[quote author="Xeoncross" date="1240178729"]Thank you for taking the time to re-document this file. I know that when I was first starting out I needed lots of help in understanding the different ways .htaccess could help with my sites.

Also, regarding hiding the PHP files I think that there is a better way to do it. The goal is to hide anything that contains a ___.php at the end (or whatever ext you use) so something like this might be better.

Code:
# If the file/dir is not real
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Or if they are trying to access a PHP file
# (Hide all PHP files so none can be accessed by HTTP)
RewriteCond %{REQUEST_FILENAME}\.php -f

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

Of course, I have not tested this method yet, but you get the idea.[/quote]

I have to get busy on some real work today, so I won't be able to test it today after all. I've added it to the above .htaccess with notations, however, that it needs testing. I included it as an "alternate" method of doing this, and have labeled both methods with method numbers and explained that they should be exclusive of one another.

I'd like someone who has time to test and confirm this method of hiding PHP files so that I don't have to include a disclaimer nor have a line that "may not work" in that file. If someone has tested or used this method and can confirm it works, then please respond in this thread and let me know. Thanks.

@simshaun: Getting a better .htaccess added to the CodeIgniter docs with a better explanation of the different things you may have to do on different servers would be awesome. The lack of it is exactly why I'm doing this. It seems that someone asks how to do this several times each week, and that's just the one's who aren't researching and finding the answer already in the forums, as it has been answered more times than I can count. However, none of the answers have been a "this answer will work for everyone, no matter your setup" type of answer, which is what we're trying to finally address.
#13

[eluser]Xeoncross[/eluser]
Another thing that could help with site SEO is to REQUIRE an ending forward slash on all pages so that our links don't half point to site.com/page and half to site.com/page/ when they are the same page.

Code:
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
#14

[eluser]charlie spider[/eluser]
Just wanted to say thanks to everyone that contributed to creating, documenting and posting this resource. I have begun to use this with all of the sites I develop, and really enjoy the thoroughness of it.
#15

[eluser]Unknown[/eluser]
This is really helpful, htaccess files are really painful to understand...

I have a problem though that I really would like to see a solution for. I am using the following line to rewrite the index.php:

Code:
RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]

If I remove the '?' i get a Bad request from the server when having %_25 (%) in the url. The ? solves that problem. But this causes other URL encoding problems in CI. When using the ? some special characters are encoded to underscores (_) or breaks the rest of the uri.

For example, using %_5b ([) breaks the rest of the URL, if it is not preceeded by %_5d (]), than it is converted to underscore. %_20 (space) and + are are also converted to underscore.

What is actually going on here?

When looking at the URL with
Code:
$_SERVER["REQUEST_URI"]
it looks fine, but when sending the URI segment through CI it gets converted as explained above.

I'm using
Code:
$config['uri_protocol'] = "AUTO";
in the config file. Changing this setting to anything else breaks the whole application, which also is weird.
#16

[eluser]theshiftexchange[/eluser]
You should include a "down for maintenance" bit in the file.

Code:
# For maintenance:
# If your IP address is the IP below - then dont re-write - it will let you through
RewriteCond %{REMOTE_ADDR} !^1\.1\.1\.1

# If the person is requesting the maintenance page, also dont rewrite (prevent loops)
RewriteCond %{REQUEST_URI} !/maintenance.html$
# Otherwise rewrite all requests to the maintenance page
RewriteRule $ /maintenance.html [R=302,L]

This lets you turn your website off, directing all trafic to "maintenance.html" - while still allowing access to a specific IP (i.e. your own so you can upload changes and test before going live again)




Theme © iAndrew 2016 - Forum software by © MyBB