Enable Wordpress login with yourblog.de/login

In: random stuff

2 Nov 2009

I thought it would be cool to not have the meta-widget on my wordpress blog enabled as there is probably little need for visitors to have a login-link visible on the start page.

If you are used to simple naming conventions from rails you expect to have the login in my case on http://blog.hyperco.de/login - but the wordpress login page sits in wp-login.php - that is wordpress' general design rule. All of the pages in the wordpress root start with 'wp-' and end with '.php' - whether you like it, or not.

So I thought, wouldn't it be nice to have apache redirect all requests to files not found on the disk to the wordpress style named files?

I assume you are using apache web server and you have the RewriteEngine aka mod_rewrite enabled, then this will do the trick:

RewriteEngine on RewriteCond %{LA-U:REQUEST_FILENAME} !-f RewriteCond %{LA-U:REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^(.*)\.php$ RewriteRule ^/(.*)$ /wp-$1.php [R=307]

This peace of code you can easily be pasted into your vhost config or .htaccess file or whatever else config file you are using.

    Explanation - line by line

  1. in line one we enable the RewriteEngine
  2. apply rule only if no file on disk with this name exists
  3. apply rule only if no directory on disk with this name exists
  4. apply rule only if REQUEST_URI does NOT end on .php
  5. rewrite (redirect) by regular expression takes place in the last line after all prior conditions are met, so in our example redirect /login to /wp-login.php

Comment Form

You need to enable javascript in order to use Simple CAPTCHA.
Security Code: