htaccess long lines

The .htaccess file is a special Apache file that adjusts the way your website behaves. You can edit the existing .htaccess file on your site, or you can create a new text file in any directory and name it .htaccess.

.htaccess files contain lines of codes, which can run quite long. 

Sometimes when you edit the .htaccess file in cPanel's text editor (or in other text editors) the lines wrap and this causes a line break. This line break is a common reason for site errors.

Luckily, this is easy to fix. You can use the Code Editor built into cPanel or an offline editor to format your code.

Use cPanel's Code Editor

  1. Use your cPanel's File Manager to create a new file in the desired folder (typically you will want this in your domain's document root) You can name it what you like - for our purposes, we'll call it .htaccess.txt.
  2. Open this file by right-clicking it, then select "Code edit" from the pop-up box.

  3. Paste the desired code into this new file.
  4. Toggle the word-wrapping mode by clicking the toolbar icon as shown:

  5. You should see that your code is now properly arranged (note that you can turn word wrapping on and still see your long lines preserved as single numbered lines as demonstrated below: 

  6. Save this file.
  7. Rename the current .htaccess to .htaccess-old
  8. Refresh the page.
  9. A new, blank .htaccess file should be present in your cPanel File Manager. (The system always requires an .htaccess file - if it senses there isn't one, it will create this new, blank one.)
  10. Copy the properly formatted code from your .htaccess.txt file into the new .htaccess file.
  11. Save the .htaccess file.
  12. Test - your code should now be free from line break errors.

Using an offline text editor

  1. Open a text editor (like Notepad) and paste your desired code into a new file.
  2. Be sure that Word Wrap is off (under Format).
  3. Save this file as htaccess.txt
  4. Upload this new file to the proper directory.

Then follow steps 7 through 12 under "Use cPanel's Code Editor" above to replace the broken code with your new code.