We want to redirect most , but not all, of a website wit a 301 redirect.
Will this work or is the first line to much ?
redirect 301 / http://designers-floor.nl/
redirect 301 /index.php http://designers-floor.nl/
redirect 301 /index.php/woonbeton http://designers-floor.nl/inspiratie/
The Redirect directive will redirect any url starting with the first fragment to the second fragment. The first directive will thus redirect the entire site. (docs)
I recommend testing with temporary redirects until you have accomplished what you want, because testing with permanent redirects will cause those redirects to be cached. Once everything works as expected you can make the redirects permanent. Make sure that the most specific url is always listed first, so that it is matched first.
If you cannot accomplish your goal with just the Redirect directives, you can either use RedirectMatch (docs) or the RewriteEngine of mod_rewrite (docs).
Related
I am trying to setup a redirection with .htaccess file.
So far I have this:
Redirect 301 /temat-konfiguracja-internetu-w-a2mobile https://infomobile.pl/konfiguracja-internetu-w-a2mobile-22500
Redirect 301 /temat-konfiguracja-mms-w-a2mobile https://infomobile.pl/konfiguracja-mms-w-a2mobile-22499
Redirect 301 /temat-jak-sprawdzic-stan-konta-w-a2mobile-oraz-inne-kody-ussd-w-a2mobile https://infomobile.pl/jak-sprawdzic-stan-konta-w-a2mobile-oraz-inne-kody-ussd-w-a2mobile-1812
Redirect 301 /temat-jak-sprawdzic-swoj-numer-telefonu-w-a2mobile https://infomobile.pl/jak-sprawdzic-swoj-numer-telefonu-w-a2mobile-22497
Redirect 301 /temat-konfiguracja-apn-internetu-i-mms-samsung-galaxy-s4 https://infomobile.pl/konfiguracja-apn-internetu-i-mms-samsung-galaxy-s4-11561
Redirect 301 /forum-internet-mobilny-w-a2mobile https://infomobile.pl/internet-mobilny-w-a2mobile-31
Redirect 301 /temat-ostrzegam-roaming-nie-dziala-w-a2mobile https://infomobile.pl/ostrzegam-roaming-nie-dziala-w-a2mobile-22494
Redirect 301 /temat-stan-konta-a2mobile https://infomobile.pl/stan-konta-a2mobile-22498
Redirect 301 /temat-rozwiązany-problem-z-konfiguracja-apn-na-urzadzeniu-meizu-m2-mini https://infomobile.pl/rozwiazany-problem-z-konfiguracja-apn-na-urzadzeniu-meizu-m2-mini-1817
Redirect 301 /temat-logowanie https://infomobile.pl/logowanie-761
Redirect 301 /mapa-index.xml https://infomobile.pl/sitemap/sitemap.xml
But... for all the other pages I want to setup a whole domain redirection (so for all the pages that are not on the list I want to point aero2forum.pl to infomobile.pl). Is there any way to accomplish this?
To redirect everything else to the root of the target domain you will need to add a (mod_alias) RedirectMatch directive after your existing (mod_alias) Redirect directives.
For example:
:
# Redirect everything else to the target domain's homepage
RedirectMatch 301 ^ https://example.target/
However, it should be noted, that from a search engine perspective, multiple redirects to the homepage will likely be seen as a soft-404. (And reported as such in Google Search Console.)
This does assume that the source and target domains point to different server's. Otherwise, this will naturally result in a redirect loop. You could avoid the redirect-loop by not redirecting the homepage, eg. ^/.. However, if both domains point to the same server then you will need to convert everything to use mod_rewrite instead and explicitly check the requested hostname.
Aside: You cannot use a (mod_rewrite) RewriteRule here since it will take priority over the existing Redirect directives (regardless of the order) and end up redirecting everything to the homepage of the target domain.
I'm trying to redirect http://brisbaneamazingrace.com.au/details.html to http://www.teambonding.com.au/activities/amazing-race-brisbane which is a different domain. In my .htaccess file I have
Redirect 301 http://brisbaneamazingrace.com.au/details.html http://www.teambonding.com.au/activities/amazing-race-brisbane
But the redirect goes to http://teambonding.com.au/activities/amazing-race-brisbanedetails.html
It keeps adding the details.html to the end of the redirect url. Whats up with that?
You should use RedirectMatch for regex matching:
RedirectMatxh 301 ^/details\.html$ http://www.teambonding.com.au/activities/amazing-race-brisbane
Also test this after clearing your browser cache.
I'm trying to 301 redirect from '/en' or '/en/' to '/en/home' using .htaccess, but any attempt I do results into a redirection loop '/en/home/home/home/home/home/home...'.Shouldn't it be as simple as Redirect 301 /en /en/home?
Redirect based rule keep matching /en in redirected URL as well. You can use RedirectMatch for this with regex support:
RedirectMatch 301 ^/(en)/?$ /$1/home
Also make sure to clear your browser cache when you test this.
You have to use the full URL, example:
redirect 301 /folder_wrong/name.html http://website.com/folder-right/name.html
I have a problem with RedirectMatch 301. It works fine on the top level domain and one variable attached, i.e.
http://xenolith.ws/ redirects to xeno-mods.com
http://xenolith.ws/explore redirects fine as well
http://xenolith.ws/mods/122 does not work
My RedirectMatch looks like this:
RedirectMatch 301 ^/(.*)$ http://xeno-mods.com/$1
What am I missing?
While testing your configuration, don't use 301, see this answer Tips for debugging .htaccess rewrite rules
Depending on your configuration and where you have this RedirectMatch, the leading / will already be removed or not. You might try
RedirectMatch .* http://xeno-mods.com/$0
or
RedirectMatch .* http://xeno-mods.com$0
You can also just use Redirect
Redirect / http://xeno-mods.com/
which redirects all requests to the new domain.
Don't forget to reload in your browser, because of your previous 301 tests, the browser might have already cached some results.
When the redirect works as you expect, you can insert the 301 status code again. But without it, the testing is much easier.
I'm having a problem getting an old WordPress site page to redirect to the new basic PHP site page.
Example: The old WordPress page with no extension is at http://example.com/levelone/leveltwo/pagename
The new page is at http://example.com/directory/pagename.php.
Here are several things I've tried:
redirect 301 /levelone/leveltwo/pagename http://example.com/directory/pagename.php
This did not work at all
Then I tried redirecting the directories first, then the page, like so:
RedirectMatch 301 ^/levelone/leveltwo/ http://example.com/directory/
redirect 301 /pagename http://example.com/pagename.php
This almost worked, but gave me the right URL but without the PHP extension.
I can't just redirect an old directory to a new one because there are actually many. The example is just one. The trouble seems to be going from a non-extension page to a page with the .php extension.
Here's another thing I tried:
RedirectMatch 301 ^/levelone/leveltwo/(.*)$ /directory/$1.php
redirect 301 /pagename http://example.com/pagename.php
This gave me http://example.com/directory/pagename/.php.
Solved: I got it to work with the following:
Redirect 301 /levelone/leveltwo/pagename/ http://example.com/directory/pagename.php
The problem seemed to be with the missing forward-slash after the old page name.
Try:
RedirectMatch 301 ^/levelone/leveltwo/(.*)$ /directory/$1.php
What's probably happening is the mod_alias and mod_rewrite aren't playing nice with each other. They're both in the URI-file mapping pipeline so when one does its processing, the URI (eventhough a redirect response is what's going to ultimately happen) continues to get processed, then when the redirect happens, the URI has been mangled by mod_rewrite.
You should just stick with mod_rewrite so that you can prevent any wordpress rules from doing its thing. Add these rules above any wordpress rules you have in your htaccess file:
RewriteEngine On
RewriteRule ^/?levelone/leveltwo/(.*)$ /directory/$1.php [L,R=301]