tivadarsubotica Posted April 12, 2021 Share Posted April 12, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/312461-bilingual-mod_rewrite/ Share on other sites More sharing options...
requinix Posted April 12, 2021 Share Posted April 12, 2021 What index.php URL are the versions with /hu/ supposed to rewrite to? Quote Link to comment https://forums.phpfreaks.com/topic/312461-bilingual-mod_rewrite/#findComment-1585770 Share on other sites More sharing options...
tivadarsubotica Posted April 13, 2021 Author Share Posted April 13, 2021 (edited) 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 April 13, 2021 by tivadarsubotica Quote Link to comment https://forums.phpfreaks.com/topic/312461-bilingual-mod_rewrite/#findComment-1585794 Share on other sites More sharing options...
requinix Posted April 13, 2021 Share Posted April 13, 2021 /vojvodjanski.html -> /index.php?c=vojvodjanski /vojvodjanski/drustvo.html -> /index.php?c=vojvodjanski&kategorija=drustvo /hu/vojvodjanski.html -> ??? Quote Link to comment https://forums.phpfreaks.com/topic/312461-bilingual-mod_rewrite/#findComment-1585795 Share on other sites More sharing options...
tivadarsubotica Posted April 21, 2021 Author Share Posted April 21, 2021 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 -> ??? /hu/vojvodjanski.html -> /index.php?lg=hu&c=vojvodjanski Quote Link to comment https://forums.phpfreaks.com/topic/312461-bilingual-mod_rewrite/#findComment-1586029 Share on other sites More sharing options...
tivadarsubotica Posted April 21, 2021 Author Share Posted April 21, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/312461-bilingual-mod_rewrite/#findComment-1586030 Share on other sites More sharing options...
Solution requinix Posted April 21, 2021 Solution Share Posted April 21, 2021 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] Quote Link to comment https://forums.phpfreaks.com/topic/312461-bilingual-mod_rewrite/#findComment-1586031 Share on other sites More sharing options...
requinix Posted April 21, 2021 Share Posted April 21, 2021 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"> Quote Link to comment https://forums.phpfreaks.com/topic/312461-bilingual-mod_rewrite/#findComment-1586032 Share on other sites More sharing options...
tivadarsubotica Posted April 21, 2021 Author Share Posted April 21, 2021 (edited) 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 April 21, 2021 by tivadarsubotica Quote Link to comment https://forums.phpfreaks.com/topic/312461-bilingual-mod_rewrite/#findComment-1586039 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.