I want to redirect just the root of my site www.example.com to www.example2.com
but not the subfolders www.example.com/subfolder !
Is it possible?
E.G.
the following rule redirect all my site:
Redirect 301 / http://www.example2.com
To redirect just the root, you can use the following
RedirectMatch 301 ^/$ http://example2.com/
Related
I'd like to redirect www.example.com/dir/subdir/ to www.example.com but when I put the following in .htaccess:
Redirect 301 /dir/subdir/ https://www.example.com
then www.example.com/dir/subdir/ redirects to www.example.com/dir/
Help appreciated.
I have two URLs: old-site.com and new-site.com.
My root folder on the old-site.com has NO FILES in it but only the .htaccess file. I don’t want to use the old domain anymore. However, I do want to pass the link juice to the new domain. Therefore, I created 301 Redirects in the .htaccess file and put it in the root folder on the old-site.com.
Why would the Redirect 301 append the “old-site.com/…” to the new-site.com?
My entire .htaccess looks like this (I skipped a few links to shorten it):
#Begin 301 Redirects
Redirect 301 / https://www.new-site.com/
Redirect 301 /contactus https://www.new-site/contact-us/
Redirect 301 /rentals https://www.new-site/lodging/
Redirect 301 /lift.html https://www.new-site/our-rentals/boat/
Redirect 301 /rentals.html https://www.new-site/our-rentals/
Redirect 301 /map.html https://www.new-site/contact-us/
Redirect 301 /giftshop https://www.new-site/store/gift-shop/
#End 301 Redirects
I don’t have any Rewrites. The above is my entire code.
The following redirect works fine:
Redirect 301 / https://www.new-site.com/
However, any other redirect creates the following absolute path on the new-site.com with a 404 error:
If I redirect:
Redirect 301 /contactus https://www.new-site/contact-us/
It goes to:
https://www.new-site.com/old-site.com/contactus
or
If I redirect:
Redirect 301 /lift.html https://www.new-site/lift/
It goes to:
https://www.new-site.com/old-site.com/lift.html
Why would the Redirect 301 append the “old-site.com/…” to the new-site.com?
Thank you,
Derek
Your rules will not do what you need correct because of this line Redirect 301 / https://www.new-site.com/ which will match any request first and if you put it in the last it will also match any request so , if you want it to match only root use RedirectMatch to be able to use regex like this :
RedirectMatch 301 /?$ https://www.new-site.com/
By this the rest of rules will work as expected .
Note: clear browser cache the test
There was a link example.com/shop/product-1
now link is example.com/newshop/product-1
I try to wtite htaccess rule to redirect from /shop/ to /newshop/
RewriteRule ^(.*)shop(.*)$ $1newshop$2 [QSA,L,R=301,NC]
Doesn't work. Where is mistake?
You can use the following redirect
Redirect 301 /shop/ /newshop/
This will redirect /shop/.* to /newshop/.*
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]
I have this htaccess code which works fine to redirect all pro.php requests to index.php:
Redirect 301 /de/pro.php /de/index.php
Redirect 301 /en/pro.php /en/index.php
Redirect 301 /fr/pro.php /fr/index.php
BUT, is there an elegant possibility with just one line of code for manyfold directories /de /en /fr /.. ?
You can use RedirectMatch :
RedirectMatch ^/(.+)/((?!index).+)\.php$ /$1/index.php