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
- 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.
- Open this file by right-clicking it, then select "Code edit" from the pop-up box.
- Paste the desired code into this new file.
- Toggle the word-wrapping mode by clicking the toolbar icon as shown:
- 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:
- Save this file.
- Rename the current .htaccess to .htaccess-old
- Refresh the page.
- 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.)
- Copy the properly formatted code from your .htaccess.txt file into the new .htaccess file.
- Save the .htaccess file.
- Test - your code should now be free from line break errors.
Using an offline text editor
- Open a text editor (like Notepad) and paste your desired code into a new file.
- Be sure that Word Wrap is off (under Format).
- Save this file as htaccess.txt
- 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.