I have a simple .htaccess which redirect non www to www domain
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
What I need to do is to exclude the IP calling from this redirect.
In other words I need that if someone call site by IP then it won't be redirected to www domain, it will call the IP itself and visitor can navigate all the site links without the 301 redirect. This means he will still navigate the site through the IP.
Try
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
It looks to see if the host does not start with www and if so it redirects to the www URL. It won't match the IP address or any other subdomains (i.e. test.example.com)
Related
I have this .htaccess rule
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
This covers the parent domain but not the subdomain.
My subdomain has the same public folder as of parent domain.
example.com is redirected to https://example.com
But subdomain.example.com is not redirected to https://subdomain.example.com
As I said above that both points to same public folder so I want the above rule to handle both.
But I don't want to write my domain or subdomain name in htaccess rule. It shall cover any domain and any subdomain
You can do this with the HTTP_HOST header:
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
So you get it from the request rather than using the server name for the virtual host. Also simplifying the regex since you’re not using the capture.
Goto your subdomain folder
Create .htaccess file in this folder
and paste this code:
just copy and paste this code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I could redirect subdomain to subdirectory:
sub.domain.com > www.domain.com/sub
By using:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.domain.com [NC]
RewriteRule (.*) www.domain.com/sub/$1 [R=301,L]
However, the page at www.domain.com/sub displayed nothing but this:
Index of /sub
Parent Directory
Apache Server at www.domain.com Port 80
I have a working website with contents at sub.domain.com.
How can I load the same website and make it work at www.domain.com/sub ?
Thank you.
Jon is right, you need to move the content. Then you just need to fix your redirect by adding http:// in front of the target domain to redirect incoming requests from the old subdomain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/sub/$1 [R=301,L]
I have 2 TLDs example.com and example.ie.
example.com and example.ie both point at the same IP address and pull the same content now we could get whacked with a ban hammer from Google for duplicate content so we want anyone accessing *.example.ie and *.example.com to be redirected to www.example.com the problem is as they are both pointing at the same server the .htaccess is the same thus I don't believe we can do the usual:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
So how do we go about creating a search-engine friendly 301 redirect from *.example.ie and *.example.com to www.example.com?
I would do it like this:
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [R=301,L]
That will redirect (statuscode 301 "permantly moved") every domain which is not www.example.com to www.example.com.
The 301 redirect you posted is just fine; the HTTP header of every request (nowadays) contains the name of the host.
As an alternative, you can use rel=canonical. It's not that urgent anyway, as duplicate content on just two domains is unlikely to be a problem.
I already have a few rules set up redirecting users, like none www to www.
but google is still indexing the site ip address i would like this to be redirect to www.and the same if a user tried it
dose any one know how to write this in the htaccess file ??
Redirect any request where the host does not start with www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
I need some help on mod rewrite 301 , to redirect my old website address to the new address ,
here is my scenario
ive www.domain1.com/page1/
want to be redirect to domain2.com/page1/
ive to replace all request goes to domain1 with domain2 and keep the page after .com
so watever was after .com should be the same just replace domain1 with domain2 .
anyone can help me with this
Regards
You may want to make sure UseCanonicalName is off, lest apache replace hostnames with the site's ServerName.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain1\.com$ [NC]
RewriteRule ^(.*)$ http://domain2.com$1 [R=301]
When redirecting from one domain name to another, you should also take the www prefix into account. This Rewrite rule will match the old domain name with or without the www prefix.
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301]
or if you prefer to keep the www prefix, substitute this RewriteRule:
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301]