Wrong 301 redirects in .htaccess? WP site - wordpress

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]

Related

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.

How to redirect URL containing question mark to different domain with .htaccess

It looks like this is a common issue since there are so many related questions here but I still have not found the solution after hours of searching...
I need to do many redirects via .htaccess for an old WordPress site. It uses URL's like this:
http://oldwpsite.com/?p=11
http://oldwpsite.com/?p=12
I need to redirect them something like this:
redirect 301 /?p=11 http://newwpsite.com/renting-a-scooter/ <--Does not work
redirect 301 /?p=12 http://newwpsite.com/scooter-tips/ <--Does not work
I have confirmed redirect does work with:
redirect 301 /xx.html http://newwpsite.com/ <--- Works
I tried many variations of RewriteEngine On, RewriteCond and RewriteRule but failed every time.
How can I do a redirect with question mark like the above?
This should redirect the two pages to where you want them to go:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /\?p=11\ HTTP
RewriteRule ^ http://newwpsite.com/renting-a-scooter? [R=301,L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /\?p=12\ HTTP
RewriteRule ^ http://newwpsite.com/scooter-tips? [R=301,L]

301 Redirect Error in 2nd part of URL

I'm having two issues (which I'm sure are related) with some 301 redirects we have setup via .htaccess in WordPress.
Issue 1
We have a site whose old URLs were:
url.com/about-us/cloud-computing/
url.com/about-us/shared-services/
We have now consolidated these two pages into one page whose url is:
url.com/about/
The issue is that when you go to one of the old URLs it redirects the first part of the string, but then appends the second part to it, though it doesn't exist anymore. e.g.
url.com/about-us/cloud-computing/ RETURNS url.com/about/cloud-computing/
so about-us has changed to about (which is correct) but it is still appending the second part of the string.
Issue 2
Where URLs have changed completely and have more than one string to them, it only changes the same string. E.g:
url.com/products/summary/ has been replaced with
url.com/solutions/features/
If you try and go to the old URL, the first part of the string changes, but the second doesn't RETURNING url.com/solutions/summary/.
NB
Pages where there was only one part to the string, now redirecting to a new page with only one part to its string, work fine.
Has anyone experienced this issue of only part of the URL being changed before, or can they advise on what might be going on?
All help much appreciated in advance, below is an example of the some of the URLs from the .htaccess file. For client confidentiality we have remove all references to the company name and any products.
Regards
J
# BEGIN WordPress
<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 /about-us/ http://www.newurl.com/about/
Redirect 301 /about-us/about-product-company/ http://www.newurl.com/about/
Redirect 301 /about-us/about-us/ http://www.newurl.com/about/
Redirect 301 /about-us/cloud-computing-software-as-a-service-shared-services-company/ http://www.newurl.com/services/software-as-a-service-saas/
Redirect 301 /about-us/one-application-multiple-products/ http://www.newurl.com/legacy-pages/one-application-multiple-products/
Redirect 301 /about-us/testimonials/ http://www.newurl.com/about/
Redirect 301 /free-whitepaper-downloads/ http://www.newurl.com/download-registration/
Redirect 301 /products/product-time-recording-company/ http://www.newurl.com/solutions/time-recording/
Redirect 301 /products/product-time-recording-company/product-time-recording-detailed-summary-company/ http://www.newurl.com/solutions/time-recording/
Redirect 301 /products/product-time-recording-company/product-time-recording-video-overview-company/ http://www.newurl.com/solutions/time-recording/
Redirect 301 /html-sitemap/ http://www.newurl.com/sitemap/

301 Redirects from specific .html pages to new permalink structure failing

I've been searching online for over an hour trying to find out why my .htaccess file isn't working as expected, but all the docs and questions about .htaccess seem to say everything should be fine. i am using a wordpress site now and need to redirect some old links to *.html files to new permalinks (one by one as the naming convention has changed completely). so my .htaccess file looks like this:
# Redirects for old URLs
redirect 301 /contact_us http://rpcdev.thisisforge.com/contact/
redirect 301 /about_us http://rpcdev.thisisforge.com/about/
redirect 301 /clients http://rpcdev.thisisforge.com/work/
redirect 301 /clients/event.html http://rpcdev.thisisforge.com/work/event-retail-design/
redirect 301 /clients/identity.html http://rpcdev.thisisforge.com/work/identity-branding/
redirect 301 /clients/web.html http://rpcdev.thisisforge.com/work/web-design/
redirect 301 /clients/corp_lit.html http://rpcdev.thisisforge.com/work/brochures-publications/
# BEGIN WordPress
<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
The First three are working fine, it's the ones from specific .html pages that are not. I've tried putting the code both above and below the WOrdPress code, and I've tried switching the order of my 301s so the .html redirects are first, not last. but this doesnt help. Weirdly, sometimes the corp_lit.html redirect works ok, but the others don't. i can see no rhyme or reason to this!
Is my browser or OS (windows s7) caching the 301s from the .htaccess or something, back from when they were maybe incorrectly typed? i've tried emptying browser cache and flushing DNS in command prompt, but to no avail.
Pull
Any help much appreciated.
The Redirect directive links path nodes together, so your first /clients redirect is being applied instead of the following ones, try changing it to use RedirectMatch instead
RedirectMatch 301 ^/clients/?$ http://rpcdev.thisisforge.com/work/

301 Redirect & site alias

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]

Resources