While working on your website, you may see a page saying:
Something Went Wrong!
Our apologies, but the website has encountered an error and cannot display this page at the moment.
This page means there is an error in your website’s .htaccess file. The .htaccess file controls server settings like URL rewriting and redirects, and a single invalid line can break the entire website. Your PHP code is not the cause of this error.
You may also be redirected to the InfinityFree 500 error page. This has the same cause.
Seeing “HTTP ERROR 500” from your browser instead? That means your PHP code has crashed. See HTTP ERROR 500: fixing PHP errors on your website instead.
Step 1: Confirm the .htaccess file is the cause
Rename your .htaccess file (for example, to .htaccess.bak) and open the page again. If the error page is gone, the .htaccess file is definitely the problem.
Keep in mind that a website can have multiple .htaccess files. The server reads the .htaccess file in the folder of the page you’re opening and in every folder above it, up to htdocs. Any of them can cause the error.
Unfortunately, the server doesn’t tell you which line is broken. The steps below can help you find it.
Step 2: Fix the .htaccess file
Replace it with a fresh copy
If the .htaccess file came with your software, replace your current file with a fresh copy of the original. For WordPress, you can copy the default rules from the WordPress documentation.
Undo recent changes
Did you recently change the .htaccess file? Then those changes are the most likely cause. Revert them, or disable the lines by adding a # at the start of each line, and check the page again.
Replace it with a fresh copy
If the .htaccess file came with your software, download a fresh copy and replace your current file with it. In WordPress, you can also delete the .htaccess file and go to Settings > Permalinks and click Save Changes to generate a new one.
Check code you copied
.htaccess rules are very sensitive to typos, spaces and line endings. If you copied rules from a web page or document:
- Make sure you copied the full snippet. An incomplete snippet can break the file.
- Turn off any translation tools first. They can mangle code snippets or translate keywords in the code itself.
- Be careful with word processors, which can replace straight quotes with curly quotes.
- Open the file in the file manager to check it. Different operating systems use different line endings, and what looks fine in your local editor may look different on the server.
If an example you found online doesn’t work, it may contain errors or rely on features that aren’t available on InfinityFree. Try a different example.
Find the broken lines
If you can’t tell which lines are broken, you can narrow it down by disabling half of the file at a time:
- Comment out the bottom half of the file and check the page.
- If the page works, the error is in the bottom half. If not, it’s in the top half.
- Repeat this with the broken half until you’ve narrowed it down to a small block or a single line.
When disabling lines, always disable complete blocks of related rules. Disabling only part of a block can break the file in a new way.
- Blocks like
<IfModule ...>start with a<...>line and end with a matching</...>line. Always disable the start, the end and everything in between together. A start without a matching end breaks the file. RewriteCondlines apply to the firstRewriteRuleline after them. When you disable aRewriteRule, also disable theRewriteCondlines directly above it.Optionslines are standalone and can be disabled individually.
Getting help
If you’ve found the broken lines but don’t know how to fix them, you can ask for help in the support channel of the software the rules came from, on a general programming forum like Stack Overflow, or on the InfinityFree forum in the Hosting Support category. Please include the contents of your .htaccess file in your question.