Forum Moderators: phranque

Message Too Old, No Replies

Over-writing .htaccess

Is there a problem?

         

Patrick Taylor

11:53 am on Jun 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In an .htaccess file I have a list of 301-redirects, which appear to be working fine, and from time to time I add one more to the list by editing the file locally and uploading it to over-write the existing one on my server. However I've read somewhere that over-writing an .htaccess file can "bring down a site". Why would that be, and if there's a risk, what is the correct way to update .htaccess?

davidpbrown

11:58 am on Jun 8, 2004 (gmt 0)

10+ Year Member



Could it be just uploaded in binary rather than ASCII doesn't work?
not sure.

DaveAtIFG

2:00 pm on Jun 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



over-writing an .htaccess file can "bring down a site"
First time I've heard that one. :)

It is imperative that .htaccess be formatted as an ASCII text file so, as davidpbrown suggests, insure your FTP uses ASCII transfer mode, not binary mode, to upload the file.

encyclo

2:04 pm on Jun 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The warnings about overwriting a .htaccess file are directed to people who have created a new .htaccess, not realising that one already exists on their system. If they overwrite the existing one, it might have contained important directives vital to the functioning of the site.

If you have created the .htaccess yourself, you know what you're doing and are just updating it, overwriting is fine.

Wizcrafts

3:58 pm on Jun 9, 2004 (gmt 0)

10+ Year Member



There is a real possibility of bringing down a website if there is an incorrectly typed command in a code-line, in .htaccess! It happened to me a few times when I added a user agent that contained spaces and paranthesis, and I didn't escape them. Also, broken pipes copied from rules found on these forums can cause server 500 errors.

Here is an example of a white space issue that will cause a 500 lockout on most Apache servers:


RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.0 (compatible)$ [NC,OR]

It should be escaped thusly:

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3\.0\ \(compatible\)$ [NC,OR]

Here is a code snippet that had solid pipes in my .htaccess, but had them changed to broken pipes by the Forum:

RewriteCond %{HTTP_USER_AGENT} Cowbot¦Downloader¦httrack¦larbin¦NaverRobot¦QuepasaCreep¦Siphon [NC,OR]

The broken pipes can cause a 500 server error.

Wiz

grandpa

7:11 am on Jun 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As has been mentioned, the biggest risk you might face is from a poorly written directive. Here's my solution. Copy the existing htaccess from the server, modify it as needed, rename it to htaccess_A1 and send it back to the server. Then I rename the existing htaccess to htaccess-SAVE, and rename the A1 version to the real deal.

If I can access my site, and everything works as far as the changes that were made, then I can safely delete the SAVE version. If something is broken, it's a quick fix to revert back to the SAVE version.

Another reason I use this procedure is because I dynamically add bans to my htaccess, and I wouldn't want to overwrite any of those :)

Yes, you can crash your site by overwriting htaccess (at least I can) but a good plan will prevent a disaster.

Patrick Taylor

2:58 pm on Jun 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the helpful and informative replies. So far, so good.

Patrick