How To Fix Widgets After Changing Your WordPress SiteURL

So you finally get around to buying that domain name for your WordPress site. You export a backup of your database and do a search and replace on the database file.   But when you import the database back in, your widgets are not there.  How do you fix it?

This plugin is a lifesaver! Enough said.
Widget Fixer
 

A Quick Way to Remove /index.php From WordPress Permalinks

This assumes that you are using Lighttpd as your web server.  But this trick should work with all web servers.

If you are using Lighttpd, add the following line to your site settings in lighttpd.conf.

server.error-handler-404 = "/index.php"

You now need to restart Lighttpd.

sudo service lighttpd restart

Now login to your wp-admin console and change the permalink URL to resemble the following.

http://my-wordpress-url.com/%postname%/

That’s it!   You’re done.   The simple, easy, elegant way to get WordPress to work without showing the index.php.

Update: If you do not wish to use the 404 trick, there is another way to accomplish the same thing by using a mod_rewrite rule. The following example illustrates how to use mod_rewrite to accomplish the same thing as we did above with the 404 error handler.

url.rewrite-once = (
	"^/(wp-content|wp-includes|wp-admin|.*\.php\??).*$" => "$0" ,
	"^/((?!(index.php)).*$)" => "/index.php/$1"
)

How to Switch WordPress from Apache to Lighttpd

If you are using Ubunutu, there are a couple of packages that you need first.  This command should get you what you need.

sudo apt-get install lighttpd php5-cgi

Now, let’s edit the /etc/lighttpd/lighttpd.conf file.  You need to add mod_fastcgi to your server.modules line.  It should look something like this when you’re done.

server.modules = ( "mod_access", "mod_rewrite", "mod_fastcgi", "mod_accesslog", "mod_redirect" )

Now let’s add the fastcgi.server settings so that it knows what to do with a .php page.

fastcgi.server = (
    ".php" =>
       ( "localhost" =>
          (
              "socket" => "/tmp/php-fastcgi.socket",
              "bin-path" => "/usr/bin/php-cgi"
          )
       )
)

Now we need to make index.php pages part of the normal start pages.

server.indexfiles = ( "index.html", "index.php" )

Lastly, we simply need to change the document-root to point to our wordpress installation.   It should look something like this.

server.document-root = "/var/www/wordpress"

Now run these few commands to stop Apache, make sure it doesn’t start again, start Lighttpd, and make sure it automatically starts for you.

sudo service stop apache2
sudo service start lighttpd
update-rc.d apache2 remove
update-rc.d lighttpd defaults

That’s it!    Enjoy WordPress running on Lighttpd!