500 server error related to mod_rewrite pretty permalink nightmare
-
People, I have been banging my head into the wall for awhile about getting those annoying “Internal Server Error – 500” with my WordPress 2.7 install.
Technically, its a server misconfig so WordPress says its not their problem and your host will say its a misconfig of your web app so its not their problem.
Here is the story. The problem tends to be a modification of the .htaccess file. This file is modded when you choose to have ‘pretty’ permalinks. Normally, in a PHP based program like WordPress, urls look like this:
https://www.mysite.com/?id=1573
Emphasis on that question mark because thats how PHP sends variables through the URI string. Anyway, beyond the discussion here a bit but its good you know the background.
So, WordPress is modifying the underlying URI automatically but its not doing this through wordpress. It modifies your .htaccess file associated with Apache on your webhost’s main domain. You might not see this file at first because its hidden but make sure your FTP program is set to see hidden files.
Once you can see this file, open it in a text editor. You will likely see this (among other things in there):
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
For some reason beyond my intelligence, this above piece of code sends Dreamhost servers and possibly others into a shitfit. All your posts will come back with an internal server 500 error. If you check your error logs you will see the reason:
[Fri Jan 09 11:19:05 2009] [error] [client 24.126.106.34] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if necessary. [Fri Jan 09 11:19:05 2009] [error] [client 24.126.106.34] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
This means the wordpress mod of the .htaccess file did not work properly. Each time wordpress is publishing your given entry, this mod_rewrite command falls into an endless loop that apache wisely has enough sense to create a failsafe for. So, the wordpress ‘publishing’ of your posts never happens. It can’t use the question mark php method and the pretty permalink method bombs – so no post can publish. This is the root of the 500 error.
Ok, so now we know whats up what do we do? Luckily there are some smarter gentlemen than I on the internet and they have devised an easy solution.
1) BEFORE DOING ANYTHING – BACKUP YOUR DB!
2) Now, go into wordpress > settings > permalinks
3) Set it to one of the pretty permalink settings like //year/month/’
4) Open a text editor on your PC/Mac and open the .htaccess file you downloaded from your webserver
5) Find this piece of code:# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
6) Replace it with this piece of code, courtesy of Scott Yang:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ /index.php/$1 [L,QSA] </IfModule>
7) Upload this code into the main domain root directory on your server and you’re done.
Everything should work, although you may need to republish your posts if you use the static wordpress publishing option
- The topic ‘500 server error related to mod_rewrite pretty permalink nightmare’ is closed to new replies.