Forum Moderators: phranque
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]
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
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]
RewriteCond %{QUERY_STRING} ^limba=(Romana¦Englesa¦Germana¦Franceza¦Italiana)&?
RewriteRule ^(index\.php)?$ http://www.example.com/? [R=301,L]
Jim
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]
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]
Jim
I used the new code you gave and it works fine. Thanks a lot.
Understand that example.com/Englesa/content.php must be an existing file if you intend to map a URL to it.
Jim
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:
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
Jim
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