Redirecting www to non www in subfolder

Redirecting www to non www in subfolder - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, 301-redirect, no-www, subdirectory, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I have Joomla installed on root folder and another Joomla installed on a subfolder.
I want to redirect www to no-www in subfolder by this code in blog .htaccess:



RewriteCond %HTTP_HOST ^(www.example.com)?$
RewriteRule ^(.*)$ http://example.com/blog/$2 [R=301,L]


It worked for root redirect but when I want browse internal page it redirect the page to home page.


Solution :

Try this in your .htaccess inside your subfolder:



RewriteCond %HTTP_HOST ^www.example.com [NC]
RewriteRule (.*) http://example.com/blog/$1 [R=301,L]

Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect