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]
Related
I want to redirect my non www domain to www and to a subfolder
I was able to redirect the domain to the subfolder with this code
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule !^subdir/ /subdir%{REQUEST_URI} [L,NC]
now I want to redirect my domain to www. how do I do that?
if I try to add www infront of my doman it still shows a non-www domain
You can use this :
RewriteEngine on
#redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^.*$ http://%1%{REQUEST_URI} [NE,L,R]
# rewrite /root to subfolder
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule !^subdir/ /subdir%{REQUEST_URI} [L,NC]
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]
I want to redirect example.com to example2.com, except for example.com/wp-admin
How do I redirect all pages on example.com to example2.com except for the subdirectory example.com/wp-admin?
I've tried:
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^wp-admin/$ [NC]
RewriteRule (.*)$ https://example2.com/$1 [R=301,L]
</IfModule>
but this does not work.
Help appreciated.
You can use this rule in site root .htaccess of example.com site:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule !^wp-admin/ http://example2.com%{REQUEST_URI} [NE,R=301,L,NC]
I moved my site from blog.abc.com to www.abc.com
I want to redirect every request made to blog.abc.com to abc.com
For example:
If blog.abc.com/example.html is requested, it should redirect to www.abc.com/example.html, how can I do it via .htaccess only?
You can put this code in your htaccess (in blog.abc.com root folder)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
Using mod_rewrite you could do it like this:
RewriteEngine On
RewriteCondition %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R,L]
or if blog.example.com has its own vhost you could also use mod_alias:
Redirect / http://example.com/
I am using htaccess to redirect non-www to www like this:
user typea: mydomain.com
.htaccess redirecta to www.mydomain.com
My code is:
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
But I don't want that redirection when a user enter a subdomain: help.mydomain.com
(help.mydomain.com is directly sent in mydomain.com root)
Do you have any idea what changes I should do to get this possible?
Yes it's possible. Here's how:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]