I am working on a site which has .htaccess file in root. There is a folder named babynames. This folder also has .htaccess file. I need the code to redirect from NON WWW to WWW for this folder. Anybody comes to this folder without www should be redirected to www.

The code at /babynames/.htaccess is

RewriteEngine On RewriteBase /babynames/

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.astrolika.com/babynames/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /babynames/404.php/$1 [L,QSA]

ErrorDocument 404 /babynames/404.php

DirectoryIndex index.php

Can anybody guide me to resolve this issue.

  • What issue, precisely? – grawity Dec 8 '18 at 11:43
  • If i use https without www it does not redirected to www for folder babynames – amita734 Dec 8 '18 at 13:27

From the post Use htaccess to add www with https support:

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The second condition checks if the HTTPS environment variable (either on or off) is set to on and captures the appended s that is then available with %1. If it doesn’t match, %1 is just an empty string.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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