Helicon Ape - mod_rewrite question

Hi guys

On a server, Win2008 R2, I installed Helicon Ape in IIS.

Now on a specific site, I'd like to redirect (301 Permanent) any visitors that arrives at the site using the domain-name without www. or anything else before the domain.

So if the visitor visits shop.domain.com do nothing
If the visitor visits www.domain.com do nothing
BUT if the visitor visits doamin.com - redirect 301 to www.domain.com

Any one who can help me out here ??
Who is Participating?
Brad HoweConnect With a Mentor DevOps ManagerCommented:

If APE is setup properly and mod_rewrite is enabled, then a simple .htacess rule will suffice. You can add this to your Root folders (.htaccess) file.

RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [NC]
rewriterule ^(.*)$ http://www.domain.com/$1 [NC,R=301]


Now, if mod_rewrite is all you need and your are just trialing APE, you can install the free module, IIS URL Rewrite to do the same thing.

IIS URL Rewrite

You can also use Microsoft's IIS URL Rewrite module as well. For example, a very simple redirect rule will take care of that as well.

In your Websites root web.config

<rule name="Canonical Host Name" stopProcessing="true">
  <match url="(.*)" />
    <add input="{HTTP_HOST}" negate="true" pattern="^domain\.com$" />
  <action type="Redirect" url="http://www.domain.com/{R:1}" redirectType="Permanent" />


Hope it helps. Let us know if you have any other issues.
trg_dkAuthor Commented:
Hi :)

I bought APE and it works for other functions, så this should be just plud and play I guess!!

Thanks for your time, will test it tonight!
trg_dkAuthor Commented:
hades666 - sorry for the (long) delay :(

How can I make it universal, så for any site in IIS7 - if the user acesses the site without any pre-domain url (www/shop/cms/etc) they always gets redirected to the current site, using www.

The code works fine but requires me to do this for 300 sites - not an option :/
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.