I have a bilingual website both in English and German. Both versions are served from the same root files like index.php, projects.php, people.php, etc.
The English versions are called via
http://myexample.com/en/index.php
http://myexample.com/en/projects.php
http://myexample.com/en/people.php
The German versions are called via
http://myexample.com/de/index.php
http://myexample.com/de/projects.php
http://myexample.com/de/people.php
For SEO reasons I like the German filenames to be Germanized:
de/projects.php -› projekte.php
de/people.php -› leute.php
Can anybody help out?
You mean something like this?
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+de/projects\.php
RewriteRule ^ /projekte.php [L,R]
RewriteCond %{THE_REQUEST} \ /+de/people\.php
RewriteRule ^ /leute.php [L,R]
RewriteRule ^projekte\.php$ /de/projects.php [L]
RewriteRule ^leute\.php$ /de/people.php [L]
Related
I multi-language site (english by default) :
/en/ gets added for english (not ok)
/fr/ gets added for french (ok)
I want to get rid of the /en/ from english URLs.
Does anyone know where this is actually added in the code, or a way of removing?
Thanks
Try with below, I am assuming you don't have front controller or something related.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/en/$
RewriteRule ^ http://example.com/ [R=302,L]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ /en/ [L]
So launched a site and made a mistake with a link and did not structure it correctly. As quite a few of these links have been picked up in Google I need to redirect the wrong links permanently without affecting the correct links and am not sure how to do it properly.
My links should be like this: /compare/itemname.html
But with the mistake they are appearing like this in Google:
/compare/itemname (without the .html part)
this was only because I missed off the .html when the links are created
dynamically and have fixed this bit now.
This is in my htaccess and works fine:
RewriteCond %{THE_REQUEST} \ /+index\.php\?keyword=([^&\ ]+)
RewriteRule ^ /compare/%1.html? [L,R]
RewriteRule ^compare/([^/]*)\.html$ /index.php?keyword=$1 [NC,L]
So how do I change from this /compare/itemname to /compare/itemname.html
where itemname can change - without messing up the above code in the
.htaccess
Or is it better at this stage just to do a 301 redirect and again how
would I pick out the urls itemname that is missing the .html ?
Thanks for any assistance
You can add a new redirect rule to add .html:
RewriteCond %{THE_REQUEST} \ /+index\.php\?keyword=([^&\ ]+)
RewriteRule ^ /compare/%1.html? [L,R]
RewriteRule ^(compare/[^.]+)/?$ /$1.html [NC,L,R]
RewriteRule ^compare/([^.]+)\.html$ /index.php?keyword=$1 [NC,L,QSA]
Try this .htaccess in your /compare/ dir
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*[^/])$ http://www.example.com/compare/$1\.html [L,R=301]
I want to use .htaccess rewrites to create the illusion of each user having their own folder on a website, when it's really just a handful of PHP files that generate all user content (often by pulling from a database):
/members/bob/avatar.jpeg points to /members/avatar.php?username=bob
/members/bob/about.html points to /members/about.php?username=bob
I'm completely lost on how to do this... I've pulled up tutorials on using the htaccess rewrite mechanics, but none of them involve changing /folder_name/variable/file_synonym to /folder_name/file_actual?var=variable. If anyone knows how to do something like that I'd be really interested, because I have no idea where to even start on this.
Try:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+members/avatar\.php\?username=([^&\ ]+)
RewriteRule ^ /members/%1/avatar.jpeg? [L,R]
RewriteCond %{THE_REQUEST} \ /+members/about\.php\?username=([^&\ ]+)
RewriteRule ^ /members/%1/about.html? [L,R]
RewriteCond ${REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^members/([^/]+)/(avatar|about)\.(jpeg|html)$ /members/$2.php?username=$1 [L]
This ended up being the solution:
RewriteEngine On
RewriteRule ^members/([A-Za-z0-9-]+)/avatar.jpeg?$ members/avatar.php?username=$1 [NC,L]
RewriteRule ^members/([A-Za-z0-9-]+)/about.html?$ members/about.php?username=$1 [NC,L]
RewriteRule ^members/([A-Za-z0-9-]+)/feed.html?$ members/feed.php?username=$1 [NC,L]
I used http://htaccess.madewithlove.be/ to test my work as I went along, to make sure that I was doing everything right. Apparently internal htaccess rewrites aren't allowed on Hostgator's shared servers, so I'll have to wait until I upgrade to really use this method.
I can successfully rewrite underscores to dashes with the following -- but I need the code to work ONLY for a certain directory, and I can't get that part to work.
WORKS:
RewriteRule ^([^_]*)_([^_]*)_(.*)$ /$1-$2-$3 [R=301,L]
RewriteRule ^([^_]*)_(.*)$ /$1-$2 [R=301,L]
DOES NOT WORK:
RewriteRule ^/media/entry/([^_]*)_([^_]*)_(.*)$ /media/entry/$1-$2-$3 [E=unscors:Yes]
RewriteRule ^/media/entry/([^_]*)_(.*)$ /media/entry/$1-$2 [E=unscors:Yes]
RewriteCond %{ENV:unscors} ^Yes$
RewriteRule ^/media/entry/(.*)$ http://domain.com/media/entry/$1 [R=301,L]
When you remove all leading / from RewriteRule patterns all should work fine (as in the first two example which work).
The the following code:
RewriteRule ^media/entry/([^_]*)_([^_]*)_(.*)$ /media/entry/$1-$2-$3 [E=unscors:Yes]
RewriteRule ^media/entry/([^_]*)_(.*)$ /media/entry/$1-$2 [E=unscors:Yes]
RewriteCond %{ENV:unscors} ^Yes$
RewriteRule ^media/entry/(.*)$ http://domain.com/media/entry/$1 [R=301,L]
There is also nice online htaccess tester which will help you out verify your configuration e.g.
The tool has some limitations though i.e. currently does not have implemented certain features like %{REQUEST_FILENAME} or %{ENV:...} but for simple rules it should be fine.
I hope that will help.
I remember that redirectmatch can't handle question marks but how can I match this url:
http://www.mysite.com/es/?lang=es&url=index.php&option=com_virtuemart&page=shop.browse&category_id=42&product_type_id=1&product_type_1etcetcetc`
to remove the lang=es&url= from before the index.php when there is a folder name present?
My problem would be solved if I could either remove the /es/ folder from the URL when presented with the ?lang=es&url= query string or I could remove the query string ?lang=es&url= from the URL when the folder is /es/
There are about 11 languages, with country codes fr, de, etc and one odd one out zh-CN. This is just past my capabilites at the moment. Thanks for taking the time to read this and any help would be greatly appreciated.
EDIT: mainly working now. I'm just having a small problem with the zh-CN language as it seems to be acting differently from the other en, fr, de etc, languages which are doing what I want, staying in English even when double clicking on another language. However, the zh-CN language redirects to the homepage with http://www.seed-city.com/?lang=zh-CN&url=index.php&zh-CN
I currently have this in my htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/../
RewriteCond %{QUERY_STRING} lang=..&url=index.php&(.*)
RewriteRule ^(.*)$ /$1index.php?%1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/(zh-CN|zh-TW)/ [NC]
RewriteCond %{QUERY_STRING} lang=([a-z]{2}|zh-CN|zh-TW)&url=index.php&(.*) [NC]
RewriteRule ^(.*)$ /$1index.php?%1 [R=301,L]
I have much more after but this is the relevant part. Thanks for your time. Natastna2.
If I understood your requirement properly this will work in your .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/es/
RewriteCond %{QUERY_STRING} lang=es&url=index.php&(.*)
RewriteRule ^(.*)$ /$1index.php?%1 [R=301,L]
Using above role a URL like this: http://www.mysite.com/es/?lang=es&url=index.php&option=com_virtuemart&page=shop.browse&category_id=42&product_type_id=1&product_type_1etc
will be redirected to:
http://www.mysite.com/es/index.php?option=com_virtuemart&page=shop.browse&category_id=42&product_type_id=1&product_type_1etc
EDIT
As per your edited section here are the rewrite rules that should work for now:
RewriteCond %{REQUEST_URI} ^/../
RewriteCond %{QUERY_STRING} lang=..&url=index.php&(.*)
RewriteRule ^(.*)$ /$1index.php?%1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/(zh-CN|zh-TW)/
RewriteCond %{QUERY_STRING} lang=(zh-CN|zh-TW)&url=index.php&(.*)
RewriteRule ^(.*)$ /$1index.php?%2 [R=301,L]