Jump to content

Bilingual mod_rewrite


tivadarsubotica
Go to solution Solved by requinix,

Recommended Posts

Hello, I'm pretty weak in mod_rewrite (too), trying to create a bilingual page.

The base link looks something like this:

1.
http://site.com/vojvodjanski.html
htaccess rule: RewriteRule ^([^/]*)\.html$ /index.php?c=$1 [L]

2.
http://site.com/vojvodjanski/drustvo.html
htaccess rule: RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?c=$1&kategorija=$2 [L]

The problem is that I should add an "hu" to each e.g:

http://site.com/hu/vojvodjanski.html

http://site.com/hu/vojvodjanski/drustvo.html ...

I haven't done this with mod rewrite yet, I need help with this, h how to solve it?

Thanks in advance,

T

Link to comment
Share on other sites

12 hours ago, requinix said:

What index.php URL are the versions with /hu/ supposed to rewrite to?

What do You mean index.php version?

Here is the full htaccess rules:

RewriteRule ^([^/]*)\.html$ /index.php?c=$1 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?c=$1&kategorija=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?c=$1&kategorija=$2&vest=$3 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?c=$1&kategorija=$2&y=$3&m=$4&d=$5&vest=$6 [L]

The full (example) link is like:

https://vojvodjanski.com/tvbecej/drustvo/2021/04/08/gradona-elnik-luka-sa-saradnicima-obi-ao-romska-naselja.html

For (Hungarian) language I will put the "hu", like this:

https://vojvodjanski.com/hu/tvbecej/kozjo/2021/04/08/a-polarmester-meglatogatta-a-roma-telepuleseket.html

Edited by tivadarsubotica
Link to comment
Share on other sites

On 4/13/2021 at 9:48 AM, requinix said:

/vojvodjanski.html -> /index.php?c=vojvodjanski

/vojvodjanski/drustvo.html -> /index.php?c=vojvodjanski&kategorija=drustvo

/hu/vojvodjanski.html -> ???

And I have another "problem", I want to remove the .html at end of every rule...

I remove the RewriteRule ^([^/]*)\.html$ /index.php?c=$1 [L] but dont work... and I want to remove from all Rules.

Link to comment
Share on other sites

  • Solution
1 hour ago, tivadarsubotica said:

/hu/vojvodjanski.html -> /index.php?lg=hu&c=vojvodjanski

RewriteRule ^(hu)/([^/]*)\.html$ /index.php?lg=$1&c=$2 [L]

This URL is very similar to the /vojvodjanski/drustvo.html because they are both "/" + word #1 + "/" + word #2 + ".html". If you want word #1 "hu" to be special then you must put this RewriteRule before the [^/]+/[^/]+.html RewriteRule.

If you want another language, like sk, then
RewriteRule ^(hu|sk)/([^/]*)\.html$ /index.php?lg=$1&c=$2 [L]

Link to comment
Share on other sites

1 hour ago, tivadarsubotica said:

And I have another "problem", I want to remove the .html at end of every rule...

I remove the RewriteRule ^([^/]*)\.html$ /index.php?c=$1 [L] but dont work... and I want to remove from all Rules.

With ^([^/]*)$ then /vojvodjanski.html -> index.php?c=vokvodjanski.html

1. Make the .html optional so that /vojvodjanski.html will continue to work and you do not create 404 errors for old URLs that are still being used.
2. Make the last [^/]* -> [^/]*? because * will match "everything" but *? will match "until".

RewriteRule ^([^/]*?)(\.html)?$ /index.php?c=$1 [L]

3. You must change the URLs on your site to not use .html. Because mod_rewrite will not change your website for you.

<a href="/vojvodjanski">

Link to comment
Share on other sites

8 hours ago, requinix said:

With ^([^/]*)$ then /vojvodjanski.html -> index.php?c=vokvodjanski.html

1. Make the .html optional so that /vojvodjanski.html will continue to work and you do not create 404 errors for old URLs that are still being used.
2. Make the last [^/]* -> [^/]*? because * will match "everything" but *? will match "until".

RewriteRule ^([^/]*?)(\.html)?$ /index.php?c=$1 [L]

3. You must change the URLs on your site to not use .html. Because mod_rewrite will not change your website for you.

<a href="/vojvodjanski">

The explanation for adding the language is very good and it works, and thak You very much. However, I have trouble leaving .html. Here's how to I use it:

index.php?c=vojvodjanski (not vojvodjanski.html)

The complete usage is here:

(index.php?c=vojvodjanski)

RewriteRule ^([^/]*)\.html$ /index.php?c=$1 [L]

(index.php?c=vojvodjanski&kategorija=drustvo)

RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?c=$1&kategorija=$2 [L]

(index.php?c=vojvodjanski&kategorija=drustvo&y=2021&m=03&d=01&vest=gradona-elnik-luka-sa-saradnicima-obi-ao-romska-naselja)

RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?c=$1&kategorija=$2&y=$3&m=$4&d=$5&vest=$6 [L]

---------------

The first Rule is: https://vojvodjanski.com/vojvodjanski.html

The second Rule is: https://vojvodjanski.com/vojvodjanski/drustvo.html

The last Rule: https://vojvodjanski.com/vojvodjanski/drustvo/2021/04/08/gradona-elnik-luka-sa-saradnicima-obi-ao-romska-naselja.html

---------------

So I want to remove all .html-s like below:

The first Rule is: https://vojvodjanski.com/vojvodjanski

The second Rule is: https://vojvodjanski.com/vojvodjanski/drustvo

The last Rule: https://vojvodjanski.com/vojvodjanski/drustvo/2021/04/08/gradona-elnik-luka-sa-saradnicima-obi-ao-romska-naselja

Sorry for a too many questions, but this is the first time that I use the mod_rewrite.

Edited by tivadarsubotica
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.