Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Multilanguage Redirects |
|
Author |
|
Sofian
Joined: 05 Jul 2024 Posts: 4
|
Posted: Fri 05 Jul '24 18:20 Post subject: Multilanguage Redirects |
|
|
We have the following issue: We used to run our domain in two languages on one domain. Like
Domain.com/english-url1
Domain.com/english-url2
Domain.com/english-url3
Domain.com/danish-url1
Domain.com/danish-url2
Domain.com/danish-url3
Now we've set the Multilanguage plugin to show all English urls still on domain.com, but all Danish urls now on domain.DK
Domain.com/english-url1
Domain.com/english-url2
Domain.com/english-url3
Domain.DK/danish-url1
Domain.DK/danish-url2
Domain.DK/danish-url3
It all works well, but both domains point into the same WordPress installation folder to make this work.
Now we need to redirect the old domain.com/Danish-urls to their new .DK place and added this to our .htaccess file:
Redirect permanent /danish-url1/ https://domain.dk/danish-url1/
The problem is that the pages run into an error “too many redirects”, most likely because both domains point into the same WordPress folder and therefore not only domain.com/Danish-url1, but also domain.dk/Danish-url1 gets redirected in an infinite loop.
We tried using absolute URLs such as
Redirect permanent https://domain.com/danish-url1/ https://domain.dk/danish-url1/
In this way there is no error, but also no redirect, so it seems the line is just ignored and doesn’t allow two absolute urls.
Also because no language code was used in the URLs before, like /dk/..., we need to address all the single pages and it cannot be solved with a generically coded rule.
I hope for a server expert this is easy to solve, for us just knowing basics it is practically impossible to figure out, thank you for your reply. |
|
Back to top |
|
mraddi
Joined: 27 Jun 2016 Posts: 152 Location: Schömberg, Baden-Württemberg, Germany
|
Posted: Sat 06 Jul '24 9:30 Post subject: |
|
|
To redirect a request matching a URL with http-code 301 (=redirect permanent) ONLY if it is not the host www.domain.dk then you might use this as a blueprint:
Code: | RewriteEngine on
RewriteCond "%{HTTP_HOST}" "!^www\.domain\.dk$" [NC]
RewriteRule "^danish-url1/" "https://www.domain.dk/danis-url1" [R=301,L]
RewriteCond "%{HTTP_HOST}" "!^www\.domain\.dk$" [NC]
RewriteRule "^danish-url2/" "https://www.domain.dk/danis-url2" [R=301,L] |
Or you identify all danish-urls (is there a generic rule? e.g. always start with ... or something like this) and put this into the RewriteRule. Also these URLs should only be redirected if NOT on www.domain.DK.
Futher reading:
https://httpd.apache.org/docs/current/mod/mod_rewrite.html
https://httpd.apache.org/docs/current/rewrite/remapping.html
Last edited by mraddi on Sun 07 Jul '24 14:19; edited 1 time in total |
|
Back to top |
|
Sofian
Joined: 05 Jul 2024 Posts: 4
|
Posted: Sun 07 Jul '24 11:57 Post subject: |
|
|
Thanks a lot mraddi, unfortunately it does not redirect.
I added this code for one concrete domain:
RewriteEngine on
RewriteCond "%{HTTP_HOST}" "!^www\.tantratemplet\.dk$" [NC]
RewriteRule "^/er-tantra-farligt-2$" "https://tantratemplet.dk/er-tantra-farligt-2/" [R=301,L]
But when calling
https://tantra-temple.com/er-tantra-farligt-2/
in the browser, it shows the domain still under tantra-temple.com.
Can you check if I replaced the placeholders correctly? Maybe the www shouldn't be there because the domain doesn't use it?
In case all seems good and should work, would you mind by any chance to take a look into the htaccess if I give you ftp access? |
|
Back to top |
|
mraddi
Joined: 27 Jun 2016 Posts: 152 Location: Schömberg, Baden-Württemberg, Germany
|
Posted: Sun 07 Jul '24 14:20 Post subject: |
|
|
Hi Sofian,
sorry - I found a typo in my post (now corrected) - the leading / was wrong.
Please try again.
And please ensure that mod_rewrite is loaded |
|
Back to top |
|
Sofian
Joined: 05 Jul 2024 Posts: 4
|
Posted: Mon 08 Jul '24 15:14 Post subject: |
|
|
Thanks again, I corrected and it still does not work, how can I check if mod_rewrite is enabled? Sorry for the total noob questions |
|
Back to top |
|
mraddi
Joined: 27 Jun 2016 Posts: 152 Location: Schömberg, Baden-Württemberg, Germany
|
Posted: Mon 08 Jul '24 19:06 Post subject: |
|
|
To load mode_rewrite you need to have a line like
Code: | LoadModule rewrite_module modules/mod_rewrite.so |
within your config.
If you are running Apache on Linux you can try to run
or
to list the loaded modules.
With
Code: | sudo a2enmod rewrite |
you can enable the needed module mod_rewrite. Of course you need to restart the service afterwards to really load this newly enabled module.
On my Windows-computer I run
Code: | httpd -t -D DUMP_MODULES |
(or http -M which is a shorter synonym for the same result) to get the same list including a line
Code: | rewrite_module (shared) |
which indicates that this module is loaded on my installation. |
|
Back to top |
|
Sofian
Joined: 05 Jul 2024 Posts: 4
|
Posted: Tue 09 Jul '24 14:58 Post subject: |
|
|
So I checked with our webhost, and they say mod_rewrite is working. So I don't know what else could be. Here again the concrete line I used based on your corrected code:
RewriteEngine on
RewriteCond "%{HTTP_HOST}" "!^www\.tantratemplet\.dk$" [NC]
RewriteRule "^er-tantra-farligt-2/" "https://www.tantratemplet.dk/er-tantra-farligt-2" [R=301,L]
In case there is any chance you could take a look, please write to info@tantra-temple.com and I will send you ftp access. We can also pay a bit, we would anyhow next look for a freelancer who can take a look into it... Thanks for your efforts so far |
|
Back to top |
|
|
|
|
|
|