I have a domain like www.example.com. I need to remove www. from specified sub folder by using a .htaccess file.

Example :

  1. www.example.com/blog should redirect to example.com

  2. All other sub folders will not redirect in url like www.example.com/forum will remain untouched.

  3. www.example.com will remain untouched.


You can put a rewrite rule like this in place in the .htaccess file. In this example "example.com" is the domain name and "subdirectory" is the name of the folder for which you want to remove the "www".

RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^subdirectory(\/.*)?$ http://example.com/subdirectory$1 [R=301,L]
  • Thanks for your answer. But it is not working because main domain and sub domain are in different server. Can you please help. – Ayan Adhikary Apr 23 '13 at 12:41
  • You could put that rule on the server with the subdomain. – Stephen Ostermiller Apr 23 '13 at 14:45

Just use your control panel and create a redirect without www

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.