: Rename translated documents into ending language initials I am building a web app and trying to add two languages to the website. So I will make the same documents ending in -gr. Some examples
I am building a web app and trying to add two languages to the website. So I will make the same documents ending in -gr. Some examples of the files look like this:
English Language paths:
example.com/index.html www.example.com/Blog.html
Greek Language path:
example.com/index-gr.html www.example.com/Blog-gr.html
Is it possible to rename the Greek files like the following:
example.com/blog-gr.html/
to something like:
example.com/blog/gr
eg: Remove the -gr of all the Greek documents and add /gr at the end.
Also only for index file, example.com/index-gr.html should be example.com/gr instead.
So i am asking for the .htaccess code to replace those greek file urls ending in -gr.html to /gr
More posts by @Margaret670
2 Comments
Sorted by latest first Latest Oldest Best
.htaccess:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)/gr$ -gr.html [NC,L]
HTML:
Add this inside the head tags of every greek file (replacing index-gr.html with your current file):
<base href="https://gragop.herokuapp.com/index-gr.html">
Change the URLs that link to the greek files to: filename.html/gr
eg: <a href="index.html/gr">Greek file </a>
Is that possible to rename the greek files to something like the following example:
example.com/blog-gr.html/
should be renamed to
example.com/blog.html/gr
eg: Remove the -gr of all the greek documents and add /gr at the end. Also only for index file, example.com/index-gr.html should be example.com/gr
Theres a couple ways you can go about it.
If you have no experience with URL rewriting, you could create folders that are named the HTML file and put the language files in that with the HTML extension.
For example:
In document root, create a folder named "blog.html". In the "blog.html" folder, create files named "en.html" and "gr.html" and place german content of the blog in "gr.html" and english content of the same blog in "en.html" Then users can access the english and german versions of your blog via the following URLs:
example.com/blog.html/en.html http://example.com/blog.html/gr.html
But if you want to make the URL more user friendly, you will want to look up URL rewriting and create URLs that map to the actual HTML content on the server. For example, you can make a rewrite rule that maps:
example.com/blog/en
to the file:
(path-to-document-root)/blogs/en.html
Personally, I think it would make more sense to have the root folder the name of the language. That way content can be sorted nicely on the server.
Maybe something like this:
example.com/gr/blog.html http://example.com/en/blog.html example.com/fr/blog.html
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.