Archive | .htaccess

Tags: , , , , , , ,

Quick Tip: Directory index forbidden by Options directive

Posted on 09 March 2011 by Chris

Getting Directory index forbidden by Options directive when trying to list files using the .htaccess?  Check to make sure that you DON’T see this in your httpd.conf or welcome.conf file.

 


Options -Indexes

 

The httpd.conf file will be at /usr/local/apachel/conf/httpd.conf on a server with cPanel and at /etc/httpd/conf/httpd.conf on a base CentOS install.  The welcome.conf should be at /etc/httpd/conf.d/welcome.conf and my not exist at all on a cPanel server.

 

I like to check for those lines in the files using these commands.

 

grep -i indexes /etc/httpd/conf/httpd.conf ; grep -i indexes /etc/httpd/conf.d/welcome.conf

 

Make sure that everything is set to +Indexes in those files and add this in the .htaccess of the folder you would like to have a list of files in!

Options +Indexes

Comments (0)

Tags: , , , , , ,

Deny and allow IP addresses using the .htaccess

Posted on 17 January 2011 by Chris

You are able to deny or allow all or selected IP addresses or ranges using the .htaccess file. Edit it with any text editor and add this code deny all IP addresses from viewing a site or folder.

order allow,deny
deny from all

You can also deny a range of IPs or one particular IP by adding the allow from directive in. The first example will allow all IPs except for 123.456.6.83.

order allow,deny
deny from 123.456.6.83
allow from all

And this will deny all IPs from the 123.456.xxx.xxx range.

order allow,deny
deny from 123.456
allow from all

Also, you can deny all IPs and only allow certain ones to access the folder. To allow only 123.456.6.83 to access the site, you can use the deny all along with an allow directive.

order allow,deny
deny from all
allow from 123.456.6.83

And for a range, you can also use the same method

order allow,deny
deny from all
allow from 123.456

Comments (0)

Tags: , , , , , , , ,

Force www in your url using the .htaccess

Posted on 15 January 2011 by Chris

To force your domain name to use www, you are able to add the following code to the .htaccess file in the document root for that domain.

RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

In the case of Randomlinux.com, if we wanted to make the URL www.randomlinux.com in the address bar all the time,  it would look like this:

RewriteCond %{HTTP_HOST} ^randomlinux.com [NC]
RewriteRule ^(.*)$ http://www.randomlinux.com/$1 [L,R=301]

Keep in mind that there are some cases that this will not work correctly.  For example, with WordPress, you cannot use this method.  With that, you have to force www using the administration panel or by modifying the database.

Comments (0)

Advertise Here
Advertise Here