Simple Rewrite & Redirect

Hi everyone!

I’ve searched and surfed this forum but still no final answer for me, searching the Google and trying on my own for hours didn’t succeed me either.

I need to perform two things with HTACCESS on my site:

  1. All URLs like http://* should be rewritten to http://*
  2. Redirect visitors from http://* to http://*

Asterik (*) should be replaced with a wildcard because I’ve got lots of sub-domains and there will be even more.

Any help is appreciated!

Thank you for your answer, dklynn

What I’m dealing here is a Wordpress engine with multisite function. The last one means that visitors can register theirselves an account and a blog which goes under their named subdomain (for example

I have a little difficult situation there and so after trying everything else, I decided to perform this sort of solution. I just want their posts under uncateogrized category to be displayed on a first page that way. Don’t ask why, there are no other easier solutions than using HTACCESS. And to make the URL seem more pretty, I decided that I want to rename it to /home. None of these directories exist physically on webspace. /cateogry/uncategorized is a static one, this doesn’t change. All that changes is the name of sub-domain, so this is the only one needing an wildcard.


First, WELCOME to SitePoint’s Apache forum!

Next, subdomains MUST be registered with a DNS to be valid - they act like separate domains. You can hand register each one OR use “dynamic mass virtual hosting”. When you are not changing the (sub)domain, you need not worry about them at all (when they’re in the same directory OR merely subjected to the same mod_rewrite in their own directory).

Next, are category and uncategorized fixed (not variables)? That makes a MAJOR difference.

Finally, make home (extensionless?) your DirectoryIndex for your (sub)domain.

For more information about mod_rewrite, check out the tutorial linked in my signature.




Thanks for the WP explanation. However, I’m sure that WP isn’t altering your httpd.conf/httpd-vhosts.conf to enable wildcard subdomains. If your host supports that, you’re set. If you’re hosting yourself: Apache’s Dynamically configured mass virtual hosting is what will resolve that problem.

As stated before, though, if all your (sub)domains are co-located, they won’t enter into any mod_rewrite code (they’re not necessary as you don’t want to alter the {HTTP_HOST} variable).

As long as category/uncategorized is static, merely use

RewriteRule ^category/uncategorized$ home [R=301,L]

I believe that you don’t have WP setup to recognize home so you’ll need to then redirect home to index.php. The only problem with that is that WP will have no clue what to serve (except from the subdomain which, I MUST assume, will resolve this issue).

As for your blank path/file task, merely remove the category/uncategorized from the above which, with the addition of the home => index.php redirection suggested above, would look like

RewriteRule ^$ home [R=301,L]
RewriteRule ^home$ index.php [L]

Piece of cake!