How to add www to the sub-folders of URL in HTACCESS - .htaccess

Here is the link of subfolder
https://example.com/abc/ i want to add www to subfolders also like this https://www.example.com/abc/

To force WWW, simply use:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Related

.htaccess redirect subdirectory to new domain

I need to redirect all pages under a specific folder to another domain with different sub folders
For example:
FROM: https://www.my.domain.com/user/myuser/test.png
TO: https://www.newdomain.com/all/allegato1.png
I have try many htaccess file but all not work
RewriteEngine On
RewriteCond %{HTTP_HOST} ^my.domain.com$ [OR]
RewriteCond %{HTTP_HOST} www.my.domain.com$
RewriteRule ^user/myuser/(.*) http://www.newdomain.com/all/$1 [R=301,L]
I insert my .htaccess into the dir my.domain.com/user/myuser/
How can i made this rule? Thanks for your help
Inside /user/myuser/.htaccess following rule should work:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?my\.domain\.com$ [NC]
RewriteRule .* http://www.newdomain.com/all/$0 [R=301,L]

Sub-domain Getting Issue with .htaccess

I have a domain "example.com" and i use following redirection code to redirect it to www in .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
it is working fine until i generate a sub-domain with that domain like "abc.example.com" but it's getting conflicts with htaccess and redirecting the sub-domain to "www.abc.example.com/abc/"
You can use:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|abc)\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

how to redirect all pages to another domain, except home page, using .htaccess

I want to redirect all pages (except for the home page) from one domain to another.
How do I do this?
This is the rule you have to add to your htaccess file.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
#if not root
RewriteCond %{REQUEST_URI} !^/?$ [NC]
#redirect
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

htaccess: non-www to www but only when no subdomain is set

I want this:
domain.tld to www.domain.tld
And other subdomains: sub.domain.tld without redirect to www.sub.domain.tld
You can put this code in your htaccess (in root folder)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.tld$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Force www to directory using .htaccess

I have this application directory
http://www.example.com/application
When user browse without www, (e.g. example.com/application), i want to force and redirect them to http://www.example.com/application
How can i achieve using .htaccess.
Thank you.
To redirect non www to www:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
To redirect www to non www, the code is similar:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]

Resources