301 Redirect & site alias - http

so I have a site I want to take offline. developmentsite.com and I want to redirect to a new site.
So I do a 301 redirect.
Redirect 301 / http://www.newssite.con. Now I want to continue working on developmentsite.com so I set it up as an alias on my own site
mysite.developmentsite.com but because the .htaccess in the main httpdocs folder both sites redirect.
How can I stop the alias redirecting?
Thanks,
Ross

You need mod_rewrite for this.
RewriteEngine On
RewriteBase /
# exclude the dev site
RewriteCond %{HTTP_HOST} !^mysite\.developmentsite\.com$
RewriteRule ^ http://www.newssite.com/ [L,R=301]

Related

Wrong 301 redirects in .htaccess? WP site

I've remade an old website website.com on Wordpress on my own subdomain remake.mydomain.com and now I would like to move it to the original domain website.com, but most of my URLs have changed so I'd like to make redirects to the new ones, but some of them do not redirect as expected (for me at least, because I'm a noob with the .htaccess file):
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Redirect 301 /en /
Redirect 301 /en/ /
# this works
...
Redirect 301 /en/wheel-alignment-2 /service/wheel-alignment/
Redirect 301 /en/wheel-alignment-2/ /service/wheel-alignment/
# redirects to /wheel-alignment-2 (page not found)
Redirect 301 /en/tire-mounting-2 /service/tire-mounting/
Redirect 301 /en/tire-mounting-2/ /service/tire-mounting/
# redirects to /tire-mounting-2 (page not found)
Redirect 301 /en/news--sales /news-and-sales/
Redirect 301 /en/news--sales/ /news-and-sales/
# redirects to /news--sales (page not found)
...
Redirect 301 /en/testimonials /
Redirect 301 /en/testimonials/ /
# this is the last redirect, redirects to /testimonials (page not found)
One even redirected to an image in /wp-content/, but I found out that Yoast SEO was causing this, so turned off "Media & attachment URLs" in "Search Appearance" > "Media" and it worked normally.
By the way, as you can see, the old site had language extension in the URL and I don't need it anymore.
The end result should be like this:
website.com/en > website.com
website.com/en/wheel-alignment-2 > website.com/service/wheel-alignment
website.com/en/news--sales > website.com/news-and-sales
Does anyone have any suggestions on what's wrong and how to do this correctly if I'm doing it wrong?
As I've said earlier I'm a noob with .htaccess and probably should use redirect conditions and rules, but as much as I google, I just can't grasp the concepts and haven't found any simple explanations for how it all works.
If I get it correctly you want to redirect to website.com from old domain, if this is the case then add following to very top of your .htaccess file and keep the rest of your rules as it is.
Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
##Redirect from remake.mydomain.com TO website.com here.
RewriteCond %{HTTP_HOST} remake\.mydomain\.com [NC]
RewriteRule ^(.*)$ http://website.com%{REQUEST_URI} [R=301,NE,L]
##Redirecting from website.com/en TO website.com
RewriteRule ^en/?$ / [NC,R=301,L]
##Redirecting from website.com/en/wheel-alignment-2 TO website.com/service/wheel-alignment
RewriteRule ^en/wheel-alignment-2/?$ service/wheel-alignment [NC,R=301,L]
##Redirecting from website.com/en/news--sales TO website.com/news-and-sales
RewriteRule ^en/news--sales/?$ news-and-sales [NC,R=301,L]

Rewrite catalog to domain without changing URL

I need to transfer URL from blog.mydomain.com to mydomain.com/blog but I don't have any experiences with mod rewrite.
The blog is on Wordpress with multisite (a was add a new site).
Website mydomain.com is in dir .\mysite\
Blog is in dir .\wordpress\
I created subdomain blog.mydomain.com and use dir .\wordpress\
I put .htaccess file into dir .\mysite\
In Wordpress I created a new site for URL mysite.com\blog and used Domain Mapping plugin
I need to use blog from url mydomain.com\blog\wordpress_urls
# Redirect and keeep old url mydomain.com/blog/ => blog.mydomain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com/blog
RewriteRule ^(.*) http://blog.mydomain.com/$1 [P]
This code work but it was changing ulr. I don't use HTTPS but in future I will.
A rewrite without redirect requires enabled mod_proxy, as well as mod_rewrite and .htaccess through Apache's httpd.conf.
In your .htaccess under the DOCUMENT_ROOT, i.e. /mysite put:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
#if not already blog.mydomain.com
RewriteCond %{HTTP_HOST} !^blog\.mydomain\.com$ [NC]
#rewrite request is for blog/* to blog.mydomain.com
RewriteRule ^blog/?$ http://blog.mydomain.com/$1 [L,P,NC]
Note: You may want to specify your preferred canonical URL to avoid search engine penalties for doubled content (here a custom Wordpress sample).

htaccess redirect with exceptions

I work on a Wordpress Network. Let's say that the main site has the link www.main-site-old.com, and all the other sites in this network have links like www.main-site-old.com/site1 , www.main-site-old.com/site2 e.t.c.
I want to redirect ONLY the main site to a new domain (let's say www.main-site-new.com) and let all the others stay as they are.
I tried this one:
Redirect 301 / http://www.main-site-new.com/
but it redirects the whole domain (for example it redirects www.main-site-old.com/site1 to www.main-site-new.com/site1)
I also tried:
RewriteCond %{REQUEST_URI} !=/site1
RewriteRule ^.*$ http://main-site-new.com/$0 [R=301,L]
but nothing happened.
With mod_alias redirect you will not be able to use regex to capture a request for http://www.main-site-old.com only so, you could use another one RedirectMatch like this :
RedirectMatch 301 ^/?$ http://www.main-site-new.com
Or go to mod_rewrite by this :
RewriteEngine On
RewriteRule ^/?$ http://www.main-site-new.com [R=301,L]
Note: clear browser cache then test.

.htaccess to change the domain in the URL

I have the following two WordPress sites.
test.mysite.com
mysite.com
The uploads(images) folder is on mysite.com and I want all image URLs from test.mysite.com to be redirected to mysite.com
For example the link test.mysite.com/wp-content/uploads/2015/09/image.jpg should be redirected to mysite.com/wp-content/uploads/2015/09/image.jpg
I appreciate any help.
If you care about your website traffic and SEO. I would recommend using 301 redirection which is: RedirectMatch permanent
It's quite easy! Make an new .htaccess file at test.mysite.com > Just add this chunk of codes bellow:
RewriteEngine On
RedirectMatch permanent ^/wp-content/uploads/(.*)$ http://mysites.com/wp-content/uploads/$1
Now all images Should be 301 SEO redirected to the concerned location.
You can place this redirect rule just below RewriteBase line:
RewriteCond %{HTTP_HOST} ^test\.(mysite\.com)$ [NC]
RewriteRule ^(wp-content/uploads/.+)$ http://%1/$1 [L,NC,R=301]

Using .htaccess to redirect a domain to another URL

I have a site running wordpress, it's the full site. One of the pages is like a contact-us form located at www.ourdomain.com/contact-us/
I also have a URL like contactourdomain.com and I want it to redirect to www.ourdomain.com/contact-us/
We used to do this with a redirect on network solutions, but I prefer to have it all done right on the server if possible. I've got it sort of working but when you visit the link is still says contactourdomain.com/contact-us/ as the URL, and that breaks all the other ones.
Any suggestions?
.htaccess
Options -MultiViews
RewriteEngine on
RewriteBase /
# Rewrite
RewriteRule ^(.*)$ http://www.ourdomain.com/contact-us//$1 [L]
if you add this in .htaccess is it working?:
RewriteRule ^$ contact-us/ [R=301,L]
keep me posted..

Resources