Marco Gasi
asked on
.htaccess and SEO friendly urls in a multilanguage website
Hi everybody.
In a website I use .htaccess to write SEO friendly url and in the root directory everything works fine.
.htaccess
This way, the url mywebsite.com/vinos.php?v= sangre_de_ toro becomes mywebsite.com/vinos/sangre _de_toro.
So in the vinos.php I have:
But I have added the support for two other language replicating the website pages in two subfolders 'en' and 'it' (the main langage 'es' is in the root). But in these subfolders the rewriting doesn't work.
The pages have different names, so I have added additional rules to my .htaccess:
In a website I use .htaccess to write SEO friendly url and in the root directory everything works fine.
.htaccess
#first I drop the file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} ^(.+)\.php$
RewriteRule (.*)\.php$ /$1 [R=301,L]
#RewriteRule ^(.*)$ $1.php [QSA]
# then redirect "/vinos.php?id=xxx" to "/vinos/xxx"
RewriteCond %{THE_REQUEST} \s/vinos\.php\?v=(\w+)\s [NC]
RewriteRule ^ /vinos/%1? [R=301,L]
# internally rewrite "/vinos/xxx" to "/vinos.php?id=xxx"
RewriteRule ^vinos/(\w+)$ /vinos.php?v=$1 [L]
This way, the url mywebsite.com/vinos.php?v=
So in the vinos.php I have:
$url = explode("/", ($_SERVER["REQUEST_URI"]));
$vino_querido = end($url);
and then I use the variable $vino_querido in my sql query.But I have added the support for two other language replicating the website pages in two subfolders 'en' and 'it' (the main langage 'es' is in the root). But in these subfolders the rewriting doesn't work.
The pages have different names, so I have added additional rules to my .htaccess:
RewriteCond %{THE_REQUEST} \s/it/vini\.php\?v=(\w+)\s [NC]
RewriteRule ^ /it/vini/%1? [R=301,L]
RewriteRule ^it/vini/(\w+)$ /it/vini.php?v=$1 [L]
RewriteCond %{THE_REQUEST} \s/en/wines\.php\?v=(\w+)\s [NC]
RewriteRule ^ /en/wines/%1? [R=301,L]
RewriteRule ^en/wines/(\w+)$ /en/wines.php?v=$1 [L]
But this has no effect, the url is not rewritten and the last element of the array $url in the wines.php (and vini.php) is "wines?v=blanco_afrutado" (or "vini?v=blanco_afrutado")
ASKER
Thank you David. I'm going to read that. :)
ASKER
Mmmmm, still have to do a deep search, but the two links you suggested, although useful, are not related at all with.my technical question....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi David thank you for the explanation. I'll follow your suggestions carefully. I'll let you know as soon as possible.
BTW: no I'm not running WordPress. :)
Cheers
BTW: no I'm not running WordPress. :)
Cheers
ASKER
Hi David.
I have resturctured my website follwing Google lineguides and your suggestions. But this didn't solve my issue. But these lines of .htaccess code
When the main langiage was in the root they looked as in original question
Now, I would like how I can make them work even for subfolders... Any idea?
Thank you so much for your help.
I have resturctured my website follwing Google lineguides and your suggestions. But this didn't solve my issue. But these lines of .htaccess code
RewriteCond %{THE_REQUEST} \s/es/vinos\?v=(\w+)\s [NC]
RewriteRule ^ /es/vinos/%1? [R=302,L]
don't work. When the main langiage was in the root they looked as in original question
RewriteCond %{THE_REQUEST} \s/vinos\.php\?v=(\w+)\s [NC]
RewriteRule ^ /vinos/%1? [R=301,L]
and they worked great.Now, I would like how I can make them work even for subfolders... Any idea?
Thank you so much for your help.
ASKER
Solved! I shluld just drop the extension from the RewriteCond, replacing this:
Thank you!
RewriteCond %{THE_REQUEST} \s/vinos\.php\?v=(\w+)\s [NC]
with thisRewriteCond %{THE_REQUEST} \s/vinos\?v=(\w+)\s [NC]
Now everything works fine and thanks to your help it should also be compliant wioth Google guidelines.Thank you!
ASKER
Thank you again! :)
You can do anything you like + if you'd like to keep your life simple, just follow Google's instructions.
https://support.google.com
Best to read many Google articles about this before starting.
The search - multilingual site google webmaster - provides a good starting point.