How to: 301 Redirect from one domain to another using mod_rewrite

By StrangeWork.com: Recently I created a new E-commerce website for a client of mine. I developed the new site as a subdomain under their existing domain (ex http://newsite.domain.com). Google ended up indexing around 4000 links from the subdomain I had created, so upon launching the new site I wanted to 301 redirect the subdomain links to the primary domain of the new site.

Sounds easy right? Of course! I quickly found many sites that recommended this rewrite rule using mod_rewrite:

RewriteRule ^(.*) http://domain.com/$1 [R=301,L]

However there is a problem with this method that no article seemed to address. This works great at redirecting from the subdomain (http://newsite.domain.com) to the new domain (http://domain.com), BUT if you navigate to http://domain.com you will hit an infinite loop.

So, how do you correct this problem? Easy, you need to create a rewrite condition to only apply the rule to your old domain or the subdomain in this case. Just add the following two lines to your .htaccess file in the root of your website:

RewriteCond %{HTTP_HOST} ^(newsite.)?domain.com$
RewriteRule ^(.*) http://domain.com/$1 [R=301,L]

Now this rewrite rule will ONLY apply to anyone who hits the old subdomain at http://newsite.domain.com and 301 redirect them to http://domain.com with the entire URL structure in tact. This method is easy to apply to a stand domain as well, just replace newsite in the above example with www.

I was pretty baffled at the amount of bad information there is on this method so thought I would share the proper method with everyone. Hopefully the update rewrite rules will help anyone having the same issues I had.

WordPress Weekly Episode 22

By StrangeWork.com: Yesterday I joined Jeffro and crew for another episode of the WordPress Weekly Podcast.

WordPress Weekly Episode 22We covered a lot of topics including the release of WordPress 2.6 beta one and the launch of WPForSale.com.

Jeff also announced that he is looking for a co-host. If you are interested in co-hosting a great WordPress podcast make sure you contact him ASAP! Rumor has it there is a nice finders fee! :P

Be sure to catch the next episode of WordPress Weekly on Friday July 11th when we will be interviewing Alex King of WordPress plugin fame!

WordPress MU Aggregator Plugin

By Strangework.com: I’m excited to announce the release of my first WordPress plugin, the WordPress MU Aggregator Plugin.

This plugin will display the most recent posts from all blogs in a WordPress MU network. The Aggregator only returns blogs updated in the last 30 days.

Created for WordPress MU 1.5.1

Features:

  • Supports permalinks, non-friendly links (querystrings), or a mixture of both
  • Pulls new posts directly from the database, not an RSS feed
  • Main WordPress MU install is not displayed in the list
  • Style-less to allow for easy implementation in any theme.
  • Easy to read comments for easy edits and styling
  • More features and sidebar widgets coming soon

Installation:
Step 1.
Unzip the file and upload wordpressMU-aggregator.php to your WordPress plugin folder.

Step 2.
Active the plugin in your WordPress Admin section under the plugins menu

Step 3.
Insert this code:

<php wp_mu_aggregator(10); ?>

Anywhere in your theme. That’s it! Change the number to alter how many posts are returned.

Download: WordPress MU Aggregator Plugin v0.5

Please comment with any bugs, comments, feature requests, or hate mail!

How To: Run Apache HTTP Server and IIS on Windows Server 2003

By StrangeWork.com: This is the first article in a series of articles I plan to write on setting up a WAMP stack (Windows, Apache, MySQL, PHP) on Windows Server 2003.

I decided to install Apache HTTP Server on my dedicated Windows Server 2003 machine. I thought I would write a detailed article explaining the process for anyone else wanting to accomplish the same task. With just a few minor config changes you can easily have IIS and Apache running alongside each other on the same Windows server.

Step 1: Download Apache Server Win32 Binary (MSI Installer) from http://httpd.apache.org/download.cgi
Step 2: Install Apache with the default settings. Read the Apache Windows Help Documentation for more information.

In order to run IIS and Apache on a single server you need to specify what IP IIS and Apache will listen for port 80 on. You must have two different IP addresses available for use.

Step 3: For Apache: Edit the http.conf file to force Apache to run on a specific IP. Find the below text in your http.conf file. If you left the default install location unchanged the file will be located here:
C:Program FilesApache Software FoundationApache2.2confhttpd.conf

# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

Change the line Listen 80 to:
Listen xxx.xxx.xxx.xxx:80

xxx.xxx.xxx.xxx is the private IP address you want Apache to listen on.

Step 4: For IIS: Install the Windows 2003 support tools.
Insert your Windows 2003 CD and open up the file:
SUPPORTTOOLSSUPTOOLS.MSI
This will install additional support tools in “C:Program FilesSupport Tools”

Open up a command prompt (start menu > run > cmd)

At the command prompt, switch to the “C:Program FilesSupport Tools” folder (cd /d c:program filessupport tools)

Type the following command:

httpcfg set iplisten -i xxx.xxx.xxx.xxx

xxx.xxx.xxx.xxx is the private IP address you want IIS to listen on. This must be a different IP from the one used above for Apache.

Restart IIS and Apache for the changes to take affect. You might need to reboot depending on your server settings. Now IIS and Apache will run in harmony on the same Windows 2003 Server!

Troubleshooting Apache
If you run it to problems, the first place to start debugging is in your Apache error.log file. The file is located in your root Apache folder logs directory. The default install location is:
C:Program FilesApache Software FoundationApache2.2logserror.log

Common Errors
An attempt was made to access a socket in a way forbidden by its access permissions. : make_sock: could not bind to address xxx.xxx.xxx.xxx:80

You will receive this error in your error.log if IIS is still listening on the private IP that you set for Apache. If you followed my directions correctly an IIS reset should resolve this problem. If you are still having issues try rebooting your server.