I am using the below in my .htaccess file to redirect all traffic from an old domain to a new domain.
All traffic should go to the home page.
RewriteCond %{http_host} ^http://www.olddomain.co.uk/ [NC,OR]
RewriteCond %{http_host} ^www.olddomain.co.uk/ [NC,OR]
RewriteCond %{http_host} ^olddomain.co.uk/ [NC]
RewriteRule ^(.*)$ http://www.newdomain.co.uk/ [R=301,NC,L]
This works fine for the homepage but for the other pages this doesn't work as the urls look something like:
http://www.olddomain.org.uk/index.php?p=214&pp=3&page=Volunteer
These are redirecting to an error page as opposed to a homepage.
I want to strip everything out that comes after the first / after the domain name but I do not know how to do this.
Thanks for your time and help in advance.
You can use:
RewriteCond %{http_host} ^(www.)?olddomain\.co\.uk [NC]
RewriteRule ^ http://www.newdomain.co.uk/? [R=301,NC,L]
Related
I am trying to redirect an entire domain to a new domain except for some URL's. The 3rd and the first redirect condition is working but not the second one. RewriteCond %{REQUEST_URI} !^/file-download-search is getting redirected to the new domain and I want this not to redirect. Any help is appreciated.
# Redirect users from domain1.com to https://www.domain2.com
# Except the download center and the pdf files
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)domain1\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/file-download-search
RewriteCond %{REQUEST_URI} !^/sites/files/([^/.]+\.pdf)$
RewriteRule ^ https://www.domain2.com%{REQUEST_URI} [R=301,L]
If somebody is looking for answers this is what worked for me.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)domain1\.com$ [NC]
RewriteCond %{THE_REQUEST} !\ /file-download-search [NC]
https://www.domain2.com%{REQUEST_URI} [R=301,L]```
I am trying to redirect every URL from my old site to my new site, so that, if someone goes to say oldsite.com/about it redirects to store.newsite.com/about rather than just store.newsite.com/index.php
I tried the following code but for some reason it always takes me to store.newsite.com/index.php when I go to oldsite.com/about instead of taking me to store.newsite.com/about, and the same goes for every other path on the site. Is there something wrong with what I am putting in my .htaccess file?
Thank you!
RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://store.newsite.com/$1 [L,R=301,NC]
Just fixed it with this code
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old\.site$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.old\.site$ [NC]
RewriteRule ^(.*)$ http://store.newsite.com/$1 [R=301,L]
I'm trying to redirect all traffic coming from facebook to a specific page. In my .htacess file I have:
RewriteCond %{HTTP_REFERER} ^http://(www\.)?facebook\.com
RewriteRule ^$ /wouldyouratherquestions.php [L]
But it doesn't seem to be working. I'm new to .htacess, what am I doing wrong here?
Your RewritePattern ^$ matches the homepage only, if you want to redirect all requests ,change ^$ to ^(.*)$ in the pattern :
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?facebook\.com
RewriteCond %{REQUEST_URI} !^/wouldyouratherquestions.php
RewriteRule ^(.*)$ /wouldyouratherquestions.php [L]
RewriteCond %{REQUEST_URI} !^/wouldyouratherquestions.php is a condition to the rule it avoids rewriting the destination to itself.
I want to redirect a domain alias to a specific page on my site. I use this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^afdekfolie.be$ [NC]
RewriteRule ^(.*)$ http://www.technosales.be/wordpress/afdekfolie/ [R=301,L]
This works when entering afdekfolie.be as the alias, but not when entering www.afdekfolie.be
How do I make this work?
Thanks,
Stefaan
Because you are asking this rule to work for the host starting with afdekfolie...
Try this one
RewriteCond %{HTTP_HOST} ^(www\.)?afdekfolie\.be$ [NC]
Or you can break it into two rules
RewriteCond %{HTTP_HOST} ^afdekfolie\.be$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.afdekfolie\.be$ [NC]
ps: how is this related to the php tag?
I'm using the following to redirect traffic from an old domain to a new one:
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
It works great, but I need to actually redirect traffic going directly to the old site's home page to a different location. How do I add this exception?
Try using the following:
## Redirect for home page requests
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /oldhomepage.html [R=301,L]
## Redirect for all other requests
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/oldhomepage.html
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
Depending on where you are sending the requests for the homepage, this may need to change some, but essentially, you need to check the content of %{REQUEST_URI} for each RewriteRule.
Hope this helps...