Redirect www.domain.com/112 to www.domain.com/ using htaccess 301 redirect - .htaccess

I have thousands of URLs on my website like:
www.domain.com/112
and
www.domain.com/113
I'd like to redirect these straight to www.domain.com.
Can someone explain how I do this using the 301 Redirect with htaccess?
Thank you

RewriteEngine on
RewriteRule ^(\d+)/?$ / [R=301,L]
This will redirect any digit-based request in document root to index page

Related

How to redirect multiple URLs dynamically with htaccess?

How can I redirect each link/URL like https://example.com/blogspot/good-url to https://example.com/blog/good-url
In all links I just want to replace blogspot with blog Is this something we can achieve through .htaccess?
RedirectMatch 302 ^/blogspot/$ https://example.com/blog/$
also tried the below but doesn't seems to work:
RewriteRule ^/?blogspot/(.*)$ https://example.com/blog/$1 [R=301,L]
You can a simple Redirect for this
Redirect 302 /blogspot/ https://example.com/blog/
This will redirect all URLs from /blogspot/foobar to /blog/foobar .

htaccess redirect some partical url 301 SEO

something on our BLOG URLS have changed.
No i want to have some URL path deleted in urls.
Example:
OLD URL:
https://do-main.de/blog/entry/die-xxx-der-portrait
NEW URL:
https://do-main.de/blog/die-xxx-der-portrait
My htaccess attempt to setup:
#OLD BLOG URLS
RewriteEngine On
# anything that is equal to https://do-main.de/blog/entry/*
RewriteCond %{HTTP_HOST} ^do\-main\.de\/blog\/entry\/$
# redirects to https://do-main.de/blog/*
RewriteRule ^/?(.*)$ https://do-main.de/blog/$1 [R=301,L]
conclusion all URLS with "entry" should be only using /blog/ without /entry/
Do you understand? Can anyone help?
You can use Redirect directive.
Redirect 301 /blog/entry/ http://example.com/blog/
This will 301 redirect all requests from example.com/blog/entry/foobar to http:// example.com/blog/foobar .

Avoid Too Many Redirects on Root level 301

I'm attempting to change the .htaccess on a website such that each page redirects to a specific page on another website. I've managed to get the non-root level pages to redirect to the new domain with no problem, but however I seem to try to redirect from the root of the old website I end up getting a 'too many redirects' problem. This feels pretty key for optimizing someone's site when they've changed from a previous domain, so would be useful to know.
The code I've got working is this:
Redirect 301 /my_counselling.html newsite.org.uk/
Redirect 301 /fees_and_contacts.html newsite.org.uk//?page_id=11
Redirect 301 /qualifications.html newsite.org.uk/
Redirect 301 /resources.html newsite.org.uk/
Redirect 301 /abuse.html newsite.org.uk/
Redirect 301 /drug_and_alchol.html newsite.org.uk//?page_id=57
Redirect 301 /lgbt_sexuality.html newsite.org.uk//?page_id=13
Redirect 301 /dyslexia.html newsite.org.uk//?page_id=8
But the following attempts to match the ROOT level all fail:
Redirect 301 / newsite.org.uk/
or
RewriteRule oldsite.com/ newsite.org.uk [R=301,L,NC]
or
RedirectMatch 301 ^/ newsite.org.uk/
which are suggestions I've read.
This feels like it should be very simple. If I can just get visitors and bots that would have gone to the old site's root to now go to the new site's root I'll be done.
Thanks so much!
It looks like both domains are on the same server, in that case, You'll need to match against the olddomain using a RewriteCondition and then redirect to the newdomain if that condtion is true.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain.uk$
RewriteRule ^(.*)$ http://www.newdomain.uk/$1 [NC,L,R=301]

htaccess 301 redirect not working for new subdomain site

I'm moving my site so wanted to test a page and redirect in the htaccess file:
I wanted to redirect
http://www.martinspencephotography.co.uk/blog/yes/mini-photo-series-minimalism-gallows-hill-outside-cloughmills
to
http://landscape.martinspencephotography.co.uk/minimalism-at-gallows-hill/
using the following in the .htaccess file:
Redirect 301 /blog/yes/mini-photo-series-minimalism-gallows-hill-outside-cloughmill http://landscape.martinspencephotography.co.uk/minimalism-at-gallows-hill
It didn't works there any reason why this might not work?
Try
RewriteRule your_page.html
http://your.url.fr/yournewpage.html [R=301]
And what about
http://www.martinspencephotography.co.uk/blog/yes/mini-photo-series-minimalism-gallows-hill-outside-cloughmills http://landscape.martinspencephotography.co.uk/minimalism-at-gallows-hill/ [R=301]
So the answer was to use DRUPAL NODE...

.htaccess - redirects after a certain point in the file not working

Would be so very grateful if someone can help me with this... I have been using a .htaccess 301 redirect file on my personal side business website for a while now however after a certain point in the file, the redirects simply do not work (returning a 200 in Rex Swain's http header tool).
I've looked through the file with a fine toothcomb and where the redirects stop working there are no issues at all (e.g. the urs are exactly as they should be). Really do not know why they would stop redirecting after a certain point?
Does anyone have any thoughts / recommendations? For anyone that would be willing to help I could send the file across.
Look forward to hearing from you,
Motley
Here's the code, the last line is the redirect that doesn't work. All before this work completely fine. There are other redirects after the last one (ive just not shown them), which also do not redirect. There is also a blank line at the end of the file.
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{http_host} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain/$1 [L,R=301]
Options +FollowSymLinks
RewriteEngine on
# index.html to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
Redirect examples
Redirect 301 /spas/alexander-house/overnight-packages http://www.domain/spas/alexander-house/spa-breaks
Redirect 301 /spas/alexander-house/day-packages http://www.domain/spas/alexander-house/spa-days
Redirect 301 /spas/alexander-house/weekend-packages http://www.domain/spas/alexander-house/spa-weekends
Redirect 301 /spas/armathwaite-hall/overnight-packages http://www.domain/spas/armathwaite-hall/spa-breaks
Redirect 301 /spas/armathwaite-hall/day-packages.html http://www.domain/spas/armathwaite-hall/spa-days
Redirect 301 /spas/armathwaite-hall/weekend-packages http://www.domain/spas/armathwaite-hall/spa-weekends
Redirect 301 /spas/billesley-manor/overnight-packages http://www.domain/spas/billesley-manor/spa-breaks
Redirect 301 /spas/billesley-manor/day-packages http://www.domain/spas/billesley-manor/spa-days
Redirect 301 /spas/billesley-manor/weekend-packages http://www.domain/spas/billesley-manor/spa-weekends
Redirect 301 /spas/bishopstrow-house/overnight-packages http://www.domain/spas/bishopstrow-house/spa-breaks
Redirect 301 /spas/bishopstrow-house/day-packages http://www.domain/spas/bishopstrow-house/spa-days
Redirect 301 /spas/bishopstrow-house/weekend-packages http://www.domain/spas/bishopstrow-house/spa-weekends
Redirect 301 /spas/bovey-castle/overnight-packages http://www.domain/spas/bovey-castle/spa-breaks
Redirect 301 /spas/bovey-castle/day-packages http://www.domain/spas/bovey-castle/spa-days
Redirect 301 /spas/bovey-castle/weekend-packages http://www.domain/spas/bovey-castle/spa-weekends
Redirect 301 /spas/castlemartyr/overnight-packages http://www.domain/spas/castlemartyr/spa-breaks
Redirect 301 /spas/castlemartyr/day-packages http://www.domain/spas/castlemartyr/spa-days
Redirect 301 /spas/castlemartyr/weekend-packages http://www.domain/spas/castlemartyr/spa-weekends
Redirect 301 /spas/celtic-manor/overnight-packages http://www.domain/spas/celtic-manor/spa-breaks
Redirect 301 /spas/celtic-manor/day-packages http://www.domain/spas/celtic-manor/spa-days
Redirect 301 /spas/celtic-manor/weekend-packages http://www.domain/spas/celtic-manor/spa-weekends
Redirect 301 /spas/chewton-glen/overnight-packages http://www.domain/spas/chewton-glen/spa-breaks
Did you try moving the Redirect to a different line in the .htaccess file? If the redirects following the new line location of Redirect 301 /spas/chewton-glen/overnight-packages http://www.domain/spas/chewton-glen/spa-breaks aren't working now then you know it is this Redirect alone that is causing the problem. Did you try removing this one redirect and see if the preceding redirects now work? I bet it has something to do with the chewton-glen directory?

Resources