1

I need to edit the htaccess file on my server. Problem is, I can't find it. Any idea where it would be?

1
  • 2
    Where did you put it?
    – andol
    Jul 18, 2010 at 15:19

8 Answers 8

4

Don't. Edit the main Apache configuration file instead. (I'm assuming you have access to it because it's your server) The .htaccess file is a file that people can create to apply certain configuration directives when they don't have access to the main server configuration, but Apache can handle requests more quickly and easily when it doesn't have to bother with .htaccess files.

On Linux the main server configuration file is usually at /etc/apache2/httpd.conf or /etc/apache2/apache2.conf, and it typically uses an Include directive to incorporate other files which may be in subdirectories of /etc/apache2. If you're using a non-Linux system, I'm not sure where the config file would be, but it should be documented on the Apache website.

If you don't have access to the main server configuration, the .htaccess file should be created in the directory you want its directives to apply to.

2
  • 2
    "Don't"? What a lame answer, he didn't ask for your opinion he asked where to find the stupid file.
    – user15590
    Jul 18, 2010 at 15:04
  • @troyengel: It's not an opinion, it's the best practice as explained in the Apache documentation itself. And I did also answer the question as asked.
    – David Z
    Jul 18, 2010 at 20:37
3

It's possible it doesn't exist, but it belongs in your document root which may be /var/www, /usr/local/apache2/htdocs, /var/www/html or others. You can see what the locations are for various distributions here. You can also place it in other directories to control portions of your site differently.

1
  • Yeah, check your apache configuration file to find your document root. For me (Ubuntu) it's here: /etc/apache2/sites-available/name-of-virtual-domain. Apr 17, 2011 at 21:14
2

You create the file in each folder you want those settings to apply to.

See the Apache documentation for more information.

1

Create a file named ".htaccess" in the root level of your web accessible folder and see if that has an effect.

1
  • ah...I didn't realize I had to create one. Thanks
    – codedude
    Jul 18, 2010 at 2:21
1

If you know where your web root starts, then as an example:

find /var/www/html -name .htaccess

If you have no clue, then brute force the entire filesystem:

find / -name .htaccess

Not pretty, but it works if you have no idea where things are on your server. Be prepared to wait while it churns.

2
  • 1
    And what if there is no .htaccess file? What if there is one, but it's not in the directory the OP wants to apply directives to? What if there are several? Still, I'm going to take the high road and not downvote you because this could be useful...
    – David Z
    Jul 18, 2010 at 20:44
  • ...then the OP would follow up with these questions. He asked how do I find it, this is how you find it. Downvote me if you want out of spite, the answer is correct to the question and not in error.
    – user15590
    Jul 19, 2010 at 16:07
0

Where ever your public/htdocs folder is.

0

You may not have a .htaccess file for the portion of your server that you can see. If no file is present, then whatever settings are specified in the parent folder are applied, up to the point that the base configuration of apache is applied.

So, as ars said, if you don't see it, create it for the directory that you want to affect. And as a sidenote, if you want different settings for different folders, go for it!

0

.htaccess files can go in any directory under the document root, so there can be more than one. There can also be none. And, depending on your system configuration or FTP client, you may just not be able to see it, because it starts with a period.

Try ls -a or change the filtering options in your FTP client to show files starting with .

Docs: http://httpd.apache.org/docs/2.1/howto/htaccess.html

1
  • "any directory under the document root" - they can also be located in directories above the document root - just depends on whether .htaccess overrides have been enabled for that directory or not.
    – MrWhite
    Aug 12, 2020 at 11:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .