Redirection works BUT - .htaccess

I have set up a redirect from old domain to new domain and it works however there are links which is not redirecting properly....
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old.us$ [OR]
RewriteCond %{HTTP_HOST} ^www.old.us$
RewriteRule (.*)$ http://www.new.com/$1 [R=301,L]
</IfModule>
I am trying to redirect : www.old.us/scripts/affiliate.pl?id=505 to www.new.com
but redirects like this : www.new.com/scripts/affiliate.pl?id=505 results a 404 page.

Change your code to this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?old\.us$ [NC]
RewriteRule ^ http://www.new.com/? [R=301,L]

Related

.htaccess multiple domain redirect to once https without www

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>

.htaccess 301 Redirect Except Main Page for .html

I'm trying to redirect all URLs in www.oldexample.com/index.html to www.newexample.com/index.html except the homepage (www.oldexample.com/index.html).
I have tried this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.oldexample\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/?$ [NC]
RewriteRule ^(.*)$ http://www.newexample.com/$1 [R=301,L]
but it didn't work. It is redirecting all pages.
How can I make it work?
Please try with below,
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html
RewriteRule ^(.*)$ http://www.newexample.com/$1 [R=301,L]

Adding redirect rule to htaccess file

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.

htaccess redirecting one url to load from another

I am trying to redirect one of my URLs in my website, but I get error 404 not found
I am trying to redirect this url: http://www.stoikovstroi.com/bg/противопожарни-врати
to be loaded from this one: http://www.stoikovstroi.com/vina/index.php/protivpojarni-vrati
RewriteEngine On
RewriteCond %{HTTP_HOST} ^stoikovstroi\.com\bg\противопожарни-врати$ [OR]
RewriteCond %{HTTP_HOST} ^www\.stoikovstroi\.com\bg\противопожарни-врати$
RewriteCond %{REQUEST_URI} !^/vina/index.php/protivpojarni-vrati
RewriteRule (.*) /vina/$1/index.php/protivpojarni-vrati
Use this rule in site root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?stoikovstroi\.com$ [NC]
RewriteRule ^bg/противопожарни-врати/?$ /vina/index.php/protivpojarni-vrati [L,NC,R=302,B]
Use this rule in /vina/.htaccess directory:
RewriteEngine On
RewriteBase /vina/
RewriteRule ^((?!index\.php/).*)$ index.php/$1 [L,NC]

htaccess redirect subdomain

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]

Resources