I have a page with two domains and I want to redirect one of the domains to a specific page via htaccess
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?
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:-
Comments
Post a Comment