Ir a contenido

Fixing wordpress mod_rewrite/permalinks 404 errors


As I wrote some time ago for spanish readers, I was having HTML 404 errors in my logs (see awstats statistics before January 2008) which I wanted to solve.

My awstats collects web statistics from eldemonionegro.{com,org,es}/wordpress and eldemonionegro.{com,org,es}/gallery2. The problem should be solved in two different ways, as wordpress and gallery2 has two different approaches when rewriting URL request.
Problems in URL coming from wordpress were due to changes I did in the way that categories and some other URL staff were generated, so everything was rightly delimited.
In the other hand, problems with gallery2 arise from who knows where. With gallery2, HTLM 404 errors come from bad formed URLs, they are errors properly generated, but, those errors, wherever they come, needed to be transformed in proper URLs and as I don’t want to lose visitors, I wanted to move those, let’s say, “false URL” to good ones, so visitors are not loosed because of an external stupid engine. The point is that I solved those errors, but now others has appeared. “Stupids” are bringing me loads of fun ;).

How wordpress works is that it uses an internal rewriting system, with an external simple .htaccess in the root wordpress directory (at least in Debian with Apache2). If you want, you can see those internal rules using a plugin called internal rewrite viewer, it’s interesting.
Over this period you could also need some web server debug output activated (Apache2 in my case). Needed rules will be showed next, but use them carefully. As you should know, debuging is a terribly-horrible-madness performance killer.

# My own custom rules
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteCond %{REQUEST_URI} /wordpress/archivos/tag/(.+?)/?$
RewriteRule . /wordpress/etiquetas/%1 [R=301,L]
RewriteCond %{REQUEST_URI} /wordpress/archivos/category/(.+?)/?$
RewriteRule . /wordpress/tema/%1 [R=301,L]
</ifmodule>
# End Custom Rules
# Rules automatically generated by wordpress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress

Be careful of %{REQUEST_URI} instead of %{THE_REQUEST}

# In Debian my wordpress conf is saved into
# /etc/apache2/sites-enabled/wordpress.conf
<IfModule mod_rewrite.c>
RewriteLog “/var/log/apache2/rewrite.log”
# RewriteLogLevel 5
</IfModule>

If anyone’s interested in gallery2, I could show my suboptimal rules

Etiquetas: , , , , , , , , , ,