Forum Moderators: phranque

Message Too Old, No Replies

5 languages site, need to redirect all 5 links to root

5 languages site, need to redirect all 5 links to root

         

balanel

3:32 pm on Aug 28, 2009 (gmt 0)

10+ Year Member



The site have 5 languages, how do i redirect all of them to www[dot]example[dot]com ?

they look like this:
/index.php?limba=Romana
/index.php?limba=Engleza
/index.php?limba=Germana
/index.php?limba=Franceza
/index.php?limba=Italiana

i would like to redirect all of them to www.example.com/

I have some other pages, also in 5 languages:

/tarife.php?limba=Engleza <-- this should go on www.example.com/tarife.php
/pensiune.php?limba=Engleza <-- this should go on www.example.com/pensiune.php
/contact.php?limba=Engleza <-- this should go on www.example.com/contact.php

what should i use to redirect all those ?!
all i want to do is to remove that line (?limba=Engleza) where the language is specified and only show clean url, like /tarife.php , /pensiune.php , /contact.php .

thank you in advance,

good day

[edited by: jdMorgan at 12:10 pm (utc) on Sep. 2, 2009]
[edit reason] example.com [/edit]

jdMorgan

5:15 pm on Aug 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use a RewriteCond in a mod_rewrite RewriteRule to check %{QUERY_STRING} for the language query, and then add a "?" to the substitution address in the RewriteRule.

See the Apache mod_rewrite documentation (often available in your language from university Web sites).

Jim

balanel

5:23 pm on Aug 28, 2009 (gmt 0)

10+ Year Member



man, i don't understand, it would be nice if you could give me the code, because i have no univerity in romania to provide such documentation.

thanks alot,

balanel

6:01 am on Aug 30, 2009 (gmt 0)

10+ Year Member



please, i am in desperate need to get this right and i've searched all over, tried everything, but still nothing.

any help is appreciated.

Thanks in advance

jdMorgan

2:30 pm on Aug 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please review our Apache Forum Charter [webmasterworld.com]. We can help you here, and would very much like to do so. However, our purpose is to help you learn, and we cannot write your code for you.

I provided the basic framework above that you can use while referencing the Apache mod_rewrite documentation to make an attempt to solve this problem. Once you've done that and are conversant with the terminology, then discussion will become possible, and a quick solution can be found.

If you do not wish to invest time or effort into finding a solution yourself, there are many other forums where you may be able to get ready-made coded solutions -- of varying quality.

Jim

balanel

9:57 am on Aug 31, 2009 (gmt 0)

10+ Year Member



Thanks a lot for your help. Using this code I managed to solve the problem

RewriteCond %{QUERY_STRING} ^limba=Romana
RewriteRule (.*) http://www.example.com/? [R=301,L]

but now im facing with another one. I have 4 more language pages like this that I want to redirect to a url like root/English, root/Italian, etc. I've looked all over the web but couldnt find any clue.
I understand I should study more and I will but right now time is pressing me. Believe me I dont just stand waiting for an answer. Im trying to find it but nothing...

Thank you for your time.

[edited by: engine at 10:37 am (utc) on Aug. 31, 2009]
[edit reason] please use example.com [/edit]

balanel

11:14 am on Aug 31, 2009 (gmt 0)

10+ Year Member



I was all wrong... It doesnt help me. Now, every link that has 'limba=Romana' in it is redirected to root and its content which isnt good because i have different content in different pages with 'limba=Romana'. It seems impossible for me to get this right and I really want to understand but I cant. Please, please, help! Im willing to pay for this... I promise to keep coming back and learn to do things because, i will need it in other projects.
Thank you again for your time.

jdMorgan

11:37 am on Aug 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use a more specific URL-path pattern in your RewriteRule, so that only "example.com/?limba=Romana" and "example.com/index.php?limba=Romana get redirected:

RewriteCond %{QUERY_STRING} ^limba=Romana&?
RewriteRule ^(index\.php)?$ http://www.example.com/? [R=301,L]

Jim

jdMorgan

11:43 am on Aug 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To handle all five languages, you can use the local "OR" function (after reading the important note below):

RewriteCond %{QUERY_STRING} ^limba=(Romana¦Englesa¦Germana¦Franceza¦Italiana)&?
RewriteRule ^(index\.php)?$ http://www.example.com/? [R=301,L]

Important: Replace the broken pipe "¦" characters with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

balanel

6:51 am on Sep 1, 2009 (gmt 0)

10+ Year Member



Ok! It worked for the romanian part... Thanks! The code is this:

RewriteCond %{QUERY_STRING} ^limba=(Romana)&?
RewriteRule ^(index.php)?$ http://www.example.com/? [R=301,L]
RewriteCond %{QUERY_STRING} ^limba=(Romana)&?
RewriteRule ^(tarife.php)?$ http://www.example.com/tarife.php? [R=301,L]
RewriteCond %{QUERY_STRING} ^limba=(Romana)&?
RewriteRule ^(pensiune.php)?$ http://www.example.com/pensiune.php? [R=301,L]
RewriteCond %{QUERY_STRING} ^limba=(Romana)&?
RewriteRule ^(contact.php)?$ http://www.example.com/contact.php? [R=301,L]
RewriteCond %{QUERY_STRING} ^limba=(Romana)&?
RewriteRule ^(istoric.php)?$ http://www.example.com/istoric.php? [R=301,L]
RewriteCond %{QUERY_STRING} ^limba=(Romana)&?
RewriteRule ^(cazare.php)?$ http://www.example.com/cazare.php? [R=301,L]
RewriteCond %{QUERY_STRING} ^limba=(Romana)&?
RewriteRule ^(caiDeAcces.php)?$ http://www.example.com/caiDeAcces.php? [R=301,L]
RewriteCond %{QUERY_STRING} ^limba=(Romana)&?
RewriteRule ^(despre.php)?$ http://www.example.com/despre.php? [R=301,L]
RewriteCond %{QUERY_STRING} ^limba=(Romana)&?
RewriteRule ^(asezare.php)?$ http://www.example.com/asezare.php? [R=301,L]

So for the romanian part, everything is going great. Buut... Right now there are 4 other languages and if i use the same code for all the other languages I will get all redirected on the romanian page (they all have the same link only the language variable is different), and thats not good. How can I 'create' other pages for the other languages, using htaccess? Something like www.example.com/en/index.php, www.example.com/it/index.php, etc

Thank you again for your time, I really really appreciate.

[edited by: eelixduppy at 1:06 pm (utc) on Sep. 1, 2009]
[edit reason] please use example.com [/edit]

jdMorgan

1:55 pm on Sep 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We need to step back from this and ask this question first: What URLs do your pages link to? -- For example, what is the link that appears in your browser's status line when you hover over a link to "contact" on your Romanian home page?

Before going on, we need to make sure you're not doing this entirely backwards -- which is a very common problem that we see in this forum.

In the "normal" case (if your goal is to change to SEO-friendly URLs), your on-page links should be changed to link to example.com/romana/contact.php or to romana.example.com/contact.php, and not to example.com/contact.php?limba=Romana

Once a browser request for that URL arrives at your server, mod_rewrite can be used to pass that request to your script at /contact.php?limba=romana (but note that "Romana" can no longer be capitalized)

As a third step for speeding up the search engines' re-indexing of your new friendly URLs, you can also redirect direct client requests (only) for example.com/contact.php?limba=romana to example.com/romana/contact.php. But this is not required, and it must be the *last* step to be done.

It is possible that you are switching from a dynamic (script-based) site design to a static individual-HTML-page site design, but this is rare these days, which is why I am questioning it.

However, in either case, the "URL-system" of your site must be correctly and completely 'designed' before proceeding to coding.

By the way, all nine of your rules posted above can be reduced to these two rules:


RewriteCond %{QUERY_STRING} ^limba=(Romana)&?
RewriteRule ^(index.php)?$ http://www.example.com/? [R=301,L]
#
RewriteCond %{QUERY_STRING} ^limba=Romana&?
RewriteRule ^(asezare¦caiDeAcces¦cazare¦contact¦despre¦istoric¦pensiune¦tarife)\.php$ http://www.example.com/$1.php? [R=301,L]

Replace the broken pipe "¦" characters with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

balanel

8:49 am on Sep 2, 2009 (gmt 0)

10+ Year Member



What I did until now for the romanian language part of the site, looks fine because its rewriting http:www.example.com/contact.php?limba=Romana into http:www.example.com/contact.php . This works fine for my site because the default language is romanian.
My other language links look like this: http:www.example.com/contact.php?limba=Engleza . My goal is to make them look like this: http://www.example.com/Engleza/contact.php . Can it be done? And where should I start?

I used the new code you gave and it works fine. Thanks a lot.

jdMorgan

12:12 pm on Sep 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a third rule:

RewriteCond %{QUERY_STRING} ^limba=(Englesa¦Germana¦Franceza¦Italiana)&?
RewriteRule ^([^/.]+)\.php$ http://www.example.com/%1/$1.php? [R=301,L]

As before, replace the broken pipe "¦" characters with solid pipe characters before use.

Jim

balanel

12:41 pm on Sep 2, 2009 (gmt 0)

10+ Year Member



added, but now every new created links are showing 404

jdMorgan

1:05 pm on Sep 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know what that means, because I know nothing above your site. Please specify the URLs you requested (use example.com) and what script-path you expected them to be mapped to. Look at your server error log and find out what script path they *did* get mapped to.

Understand that example.com/Englesa/content.php must be an existing file if you intend to map a URL to it.

Jim

balanel

5:38 am on Sep 3, 2009 (gmt 0)

10+ Year Member



i understand that example.com/Englesa/content.php must be an existing file, but what do i do if there is no file ?

This mean i can not turn my URLs into SEO friendly URLs ?

thank you very much for your time and your help.

Have a great day

jdMorgan

1:06 pm on Sep 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> This mean i can not turn my URLs into SEO friendly URLs ?

That is correct. Mod_rewrite cannot "change" a URL.

Earlier in this thread, I mentioned that many (if not most) people try to do this 'backwards' because they think of mod_rewrite as "being in control" and overriding everything else in the world. It doesn't work like that. To explain as simply as possible:

  • The link that appears on your Web page defines the URL. This is the "real" URL, and nothing can change it unless the code on your HTML page is changed. Once published on a Web page, the URL exists -- whether or not it resolves to an existing resource at an existing domain.
  • The name of the file on your server does not define the URL, it defines only part of the filepath used on the server. A file is not a URL.
  • The most basic job of a server is to map URLs to filepaths. URLs 'map' to files, and files are 'associated' with URLs, but URLs and filepaths are never the same; Even if no mod_rewrite code is present, the server must still translate the requested URL to a filepath usable by the operating system.
  • mod_rewrite executes after a client (e.g. a browser or robot) requests a URL, and that HTTP request arrives at the server. It executes before any content is served, and before any server-side scripts are executed. It does not affect the 'text' of the URLs that appear in the links on your pages.
Therefore:
  1. If you want to change your URLs, then edit the HTML pages to change those URLs. If your site is dynamic, edit the scripts that produce those HTML pages -- or purchase a commercial "plug-in" that does this.
  2. Next, add code to your server (e.g. mod_rewrite code in .htaccess) to detect requests for those new URLs, and to translate them back into the old, unfriendly, dynamic filepath format needed to call your script(s).
  3. Finally, as an optional third step to speed up search-engines' re-indexing of your site, you can add more code to detect direct client requests for old unfriendly, dynamic URLs and redirect them to the new, friendly URL format. This is similar to, but not quite exactly what we've done above, and the code discussed so far is useful only after the first two steps described here have been done, and only after it is modified to affect only direct client requests.
More-detailed information on this subject is available in our Apache forum library [webmasterworld.com]. Of particular interest may be:

A Short Introduction and Guide to Apache Mod Rewrite [webmasterworld.com]
What you can and can not do with mod rewrite.

Changing Dynamic URLs to Static URLs [webmasterworld.com]
Implementing search engine friendly URLs with mod_rewrite

Jim

balanel

6:07 pm on Sep 3, 2009 (gmt 0)

10+ Year Member



thanks for the great job you did to me, really, it helped alot.

i think i will leave it like this and focus on the romanian version for now.

With respect,

jdMorgan

6:26 pm on Sep 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If my diagnosis of the situation is correct, then remove all of the redirects -- including the ones on your Romanian pages; You do NOT want to redirect every request resulting from clicks on your on-page links... This could have bad consequences for the health and success of your site in search engines.

Jim

balanel

7:21 pm on Sep 3, 2009 (gmt 0)

10+ Year Member



Are you sure it's not good for site's health on long term ?
I can't belive i couldn't solve the problem.
Should i hire some PHP coder to get it done ?

thank you very much for your patience and advices.

jdMorgan

12:39 pm on Sep 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you link to a URL, but then redirect all requests for that URL, then that is a signal of "low site quality," because the search engines see that "every link published on your site is wrong." You need to link to the correct URL (a URL that will not get redirected) from within your own site. It does not matter so much if other Webmasters link to "wrong" URLs and you redirect those requests, because those links and requests are coming from outside of your own site. But if every link on your own pages gets redirected, than that is considered 'sloppy design.' There is a specific 'error warning' in Google Webmasters tools about linking to redirected URLs.

Also, since every redirect terminates the current HTTP transaction and forces the client (browser or search engine robot) to ask again (using the new URL) for every resource it requests, this slows down the user- experience, clogs up you logs files (with two requests for everything instead of one), and doubles the number of client requests that your server must handle.

So yes, you should consider hiring a PHP programmer to modify the links on your pages (PHP preg_replace may come in handy), or buy an off-the-shelf 'plug-in' that can do this for you. The latter solution is to be preferred if your software is a commercial (i.e. non-proprietary) script, since the plug-in will likely work with future version upgrades of your software, whereas if you hire a programmer to fix your current software, then you will have to hire him/her again to 'patch' the next security update or version release of your software...

Jim

balanel

5:44 pm on Sep 4, 2009 (gmt 0)

10+ Year Member



the design and content is unique, it been created by a guy, especially for this site.
but i can't find the guy, because he runed away from home :) (for real)

now i have to think about paying someone to do it.

again, i am feeling very greatful to you,
thank you