I have two domains:
www.mywebsite.com
www.my-website.com
I want all traffic going to my-website.com (no www.)
In the .htaccess for www.mywebsite.com I currently have the following:
RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$
RewriteRule ^/?$ "http\:\/\/www\.my\-website\.com\/" [R=301,L]
In the .htaccess for www.my-website.com I currently have the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^111\.111\.111\.111
RewriteRule (.*) http://www.my-website.com/$1 [R=301,L]
I am looking for the correct way to write both .htaccess files so everything goes to my-website.com and prevent from running in parallel.
in www.mywebsite.com .htaccess I entered the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mywebsite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mywebsite.com$
RewriteRule (.*)$ http://my-website.com/$1 [R=301,L]
</IfModule>
in www.my-website.com I entered the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-website\.com
RewriteRule (.*) http://my-website.com/$1 [R=301,L]
Related
i have few domains:
www.xxx.com
xxx.com
www.xxx.co
xxx.co
www.xx.io
xxx.io
how to redirect all domains to https://xxx.io?
I have a redirect to https without www:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Use this rule in your .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?example.io [NC]
RewriteRule ^(.*)$ https://example.io%{REQUEST_URI} [L,R=301]
The condition checks to see if the URL is either www.example.io or exmaple.io and if it isn't, then it will rewrite to it.
I've used R=301 which is a permanent redirection. For testing purposes, I advise you change this to R or R=302, which is temporary.
Make sure you clear your cache before testing this.
you can add the following lines to your .htaccess file located at the root of your xxx.io domain:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^xxx.com$ [OR]
RewriteCond %{HTTP_HOST} ^xxx.co$
RewriteRule (.*)$ http://xxx.io/$1 [R=301,L]
</IfModule>
I have several domains pointed to my hosting. Suppose I have ex1.com, ex2.com, ex3.com pointed to my hosting. Now ex2.com is hosted on another hosting. Now I want to add a redirect rule on the htaccess file so that I can redirect ex1.com to ex2.com. What will be the code? I tried the code below but no luck :-
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ex1.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.ex1.com [NC]
RewriteRule ^(.*)$ http://www.ex2.com/$1 [L,R=301,NC]
Can anyone please inform me what I have to do?
You require Redirect 301:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
This is useful when you use www.newdomain.com as your new domain name. If the domain is different, then use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>
Obviously replace olddomain and newdomain with the correct domains.
I have two domains, autodromodifranciacorta.it and franciacortacircuit.com both pointing to the same website hosted on this IP address: 94.23.64.40.
Now i want all the content to be under one single domain, so i decided to 301 redirect all the traffic from franciacortacircuit.com to autodromodifranciacorta.it
Here is my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The redirect is not working and i have no clue why, because the syntax looks correct to me.
The .htaccess file is processed, because if i put a typo in it, i get server error.
Wha'ts wrong with it?
Your second http_host condition is wrong and it never matches if the current host is franciacortacircuit.com, You need to use an OR condition to match against 2 diffrent hosts.
#Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]
I have the following .htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mysite.co$ [NC]
RewriteRule ^(.*)$ http://www.mysite.co/$1 [R=301,QSA,L]
</IfModule>
The problem is that all subdomains get redirected to www.mysite.co/subdomain
How can I aviod this?
Your rewrite rule logic in plain speak is doing the following:
For ANY HOST other thant www.mysite.co (including foo.mysite.com, blog.mysite.com, etc..)
Permanent Redirect (301) to http://www.mysite.co/
This is the last rule to check in the .htaccess file, so bail out
To not redirect your own subdomains, the easiest and clearest way is to handle it explicitly with more rewrite conditions (see example below). For more kung fu htaccess fun try this: .htaccess Wildcard Subdomains
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mysite.co$ [NC]
RewriteCond %{HTTP_HOST} !^blog.mysite.co$ [NC]
RewriteCond %{HTTP_HOST} !^foo.mysite.co$ [NC]
RewriteRule ^(.*)$ http://www.mysite.co/$1 [R=301,QSA,L]
</IfModule>
You need to run your index.php file
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.example\.com$ [NC]
RewriteRule !^index\.php($|/) index.php/accounts/%2%{REQUEST_URI} [PT,L]
I moved my site to a new php 5.2 server with no access to apache conf files
So I had to put site's rewrite rules into an .htaccess (wildcards is open for the domain)
and I expirience a lot of issues with it now
ORIGINAL WAS
Options +FollowSymLinks
rewriteEngine on
rewriteCond $1 !^pages/
rewriteCond %{HTTP_HOST} !^www\.mydomain\.com
rewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com
rewriteRule (.*) /pages/%1/$1
rewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /pages/
rewriteRule ^pages/([^/]+)/(.*)$ http://$1.mydomain.com/$1 [R=301,L]
What changes Do I need to make ?
the whole point is that I need to redirect:
www.mydomain.com/pages/XXXXX.php ==>
XXXXX.mydomain.com/...whatever....
but also
www.mydomain.com/pages/XXXXX/...whatever.... ==> XXXXX.mydomain.com/...whatever....
The rules below should do what you requested.
However, in the first example, where does the whatever appear in the original request to www.mydomain.com/pages/XXXXX.php.
If the whatever refers to the query string, then it should work.
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
#redirect www.mydomain.com/pages/XXXXX.php to XXXXX.mydomain.com/
RewriteRule ^pages/(.+)\.php http://$1.mydomain.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
#redirect www.mydomain.com/pages/XXXXX/.whatever.. to XXXXX.mydomain.com/...whatever
RewriteRule ^pages/([^/]+)/(.*) http://$1.mydomain.com/$2 [R=301,L]
You could try the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^pages/
RewriteRule ^pages/([^/]+)(?:\.php|/(.*))$ http://$1.mydomain.com/$2 [R=301,L]
RewriteCond %{REQUEST_URI} !^pages/
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com
RewriteRule (.*) /pages/%1/$1 [L]
</IfModule>
And one more: please make sure whether you REALLY NEED the Options +FollowSymLinks directive as this might cause an internal error if not allowed or already set in httpd.conf