1

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:

  • www.example.com/index.html
  • www.example.com/Blog.html

Greek Language path:

  • www.example.com/index-gr.html
  • www.example.com/Blog-gr.html

Is it possible to rename the Greek files like the following:

  • www.example.com/blog-gr.html/

to something like:

  • www.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

2

Is that possible to rename the greek files to something like the following example:

www.example.com/blog-gr.html/

should be renamed to

www.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:

http://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:

http://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:

http://example.com/gr/blog.html
http://example.com/en/blog.html
http://example.com/fr/blog.html
  • 1
    yes i already did that before but it is time consuming, since for different folders i need to change all the paths to ../ so i added the greek files in the same directory as the english documents and renamed them to -gr. – csandreas1 Jul 4 '17 at 7:44
1

.htaccess:

    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)\/gr$ $1-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>

  • I'm not sure of the reason for the base tag? If you are changing the URLs then it would be preferable to make these root-relative instead ie. /filename.html/gr. I thought you wanted /index-gr.html to be /gr instead (special case)? If you are going through the process of changing the URLs then you could consider removing the .html extension as well? eg. /filename/gr. – DocRoot Jul 4 '17 at 8:27
  • @DocRoot I can do that as well by removing the .html (left) in the htaccess file. You think it is better to remove the .html ? – csandreas1 Jul 4 '17 at 10:13
  • Removing the .html certainly "looks" cleaner. – DocRoot Jul 5 '17 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.