I have a page with two domains and I want to redirect one of the domains to a specific page via htaccess

I have a page with two domains and I want to redirect one of the domains to a specific page via htaccess - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the I have a page with two domains and I want to redirect one of the domains to a specific page via htaccess error on your web browser. Problem :


I am using the domains ergonomi.example and fysiarbejdsliv.example



I want fysiarbejdsliv.example to redirect to https://fysiarbejdsliv.example/dansk-selskab-for-fysioterapi-i-arbejdsliv.



I have tried a lot of solutions in htaccess, but none of them are working for me.



Like:



RewriteRule ^fysiarbejdsliv.example/(.*)$ https://www.fysiarbejdsliv.example/dansk-selskab-for-fysioterapi-i-arbejdsliv/$1 [L,R=301,QSA]


Both ergonomi.example and fysiarbejdsliv.example points to the homepage as it is now. I want fysiarbejdsliv.example to redirect to https://www.fysiarbejdsliv.example/dansk-selskab-for-fysioterapi-i-arbejdsliv. Is this possible?


Solution :


RewriteRule ^fysiarbejdsliv.example/(.*)$ https://www.fysiarbejdsliv.example/dansk-selskab-for-fysioterapi-i-arbejdsliv/$1 [L,R=301,QSA]



The RewriteRule pattern (first argument) matches against the URL-path only - this does not include the hostname. So the above directive will simply never match the request and will do nothing.



However, with this directive it looks like you are trying to do something very different to what you stated in the question. In your question you state that you want to redirect fysiarbejdsliv.example (no www subdomain?) to https://fysiarbejdsliv.example/dansk-selskab-for-fysioterapi-i-arbejdsliv only. But your directive has a capturing group in the pattern and you are using a backreference in the substitution? Is this just a bad case of copy/paste or a suggestion that you are really trying to do something else? This directive looks like you are trying to redirect fysiarbejdsliv.example/<anything> to https://www.fysiarbejdsliv.example/dansk-selskab-for-fysioterapi-i-arbejdsliv/<same-anything>?



Since both domains point to the same filesystem you will need an additional condition (RewriteCond directive) to check the Host header (ie. the domain name) before making the redirect.



For example, using mod_rewrite:



RewriteEngine On

RewriteCond %HTTP_HOST bfysiarbejdsliv.example [NC]
RewriteRule ^$ https://www.fysiarbejdsliv.example/dansk-selskab-for-fysioterapi-i-arbejdsliv [R=302,L]


The above redirects http[s]://[www.]fysiarbejdsliv.example/ to https://www.fysiarbejdsliv.example/dansk-selskab-for-fysioterapi-i-arbejdsliv only.



This needs to go before any existing (or rather "conflicting") redirects/rewrites. If you have any mod_alias Redirect or RedirectMatch directives then these may need rewriting to use mod_rewrite instead.



Make sure you've cleared your browser cache before testing and only change the 302 (temporary) redirect to a 301 (permanent) when you are sure it's working OK to avoid caching issues.



you can do the following

for external site



Redirect /path/to/old/file/old.html http://www.example.com/new/file/new.html 


for local site



Redirect /path/to/old/file/old.html /path/to/new/file/new.html


Link to the reference:-




https://help.dreamhost.com/hc/en-us/articles/215747748-How-can-I-redirect-and-rewrite-my-URLs-with-an-htaccess-file-



We hope that this article has helped you resolve the domains, htaccess, redirects error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=