logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

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.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Multilanguage Redirects
Author
Sofian



Joined: 05 Jul 2024
Posts: 4

PostPosted: Fri 05 Jul '24 18:20    Post subject: Multilanguage Redirects Reply with quote

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

PostPosted: Sat 06 Jul '24 9:30    Post subject: Reply with quote

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

PostPosted: Sun 07 Jul '24 11:57    Post subject: Reply with quote

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

PostPosted: Sun 07 Jul '24 14:20    Post subject: Reply with quote

Hi Sofian,
sorry - I found a typo in my post (now corrected) - the leading / was wrong.
Please try again. Very Happy

And please ensure that mod_rewrite is loaded Very Happy
Back to top
Sofian



Joined: 05 Jul 2024
Posts: 4

PostPosted: Mon 08 Jul '24 15:14    Post subject: Reply with quote

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 Smile
Back to top
mraddi



Joined: 27 Jun 2016
Posts: 152
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Mon 08 Jul '24 19:06    Post subject: Reply with quote

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
Code:
a2query -m

or
Code:
apache2ctl -M

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

PostPosted: Tue 09 Jul '24 14:58    Post subject: Reply with quote

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


Reply to topic   Topic: Multilanguage Redirects View previous topic :: View next topic
Post new topic   Forum Index -> Apache