I have a url that looks like this: www.example.com/folder. Now, I was wondering how I can tell Apache to redirect the url to folder.example.com


The simplest solution is to place a single .htaccess file inside your /folder directory:

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^www.example\.com [NC]
  RewriteRule (.*) http://folder.example.com/$1 [R=301,L]


Please note, that your Apache needs to be configured with mod_rewrite

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.