I want to make my new website project multilingual. My idea is to redirect files to an imaginary language folder(like www.domain.com/en/sub/content.php and so on).
RewriteRule ^en/(.*)$ /$1?lang=en [L]
RewriteRule ^de/(.*)$ /$1?lang=de [L]
RewriteRule ^es/(.*)$ /$1?lang=es [L]
RewriteRule ^ru/(.*)$ /$1?lang=ru [L]
It works well for physically existing test files, even down a few folders...
But it doesn't work combined with another rewrite.
To get "www.domain.com/liga.php?whatleague=firstleague&matchday=7" to look like "www.domain.com/firstleague/2013/7/"
I used:
RewriteRule ^firstleague/2013/([0-9]+)/?$ /liga.php?whatleague=firstleague&matchday=$1 [L]
The redirect alone works fine, BUT the "lang" parameter doesn't get passed on when I add the language folder (www.domain.com/de/firstleague/2013/7/).I tried it in different order in the htaccess file, but with the same result.
PS: english is not my primary language.
You don't need another rule, just add QSA flag in you firstleague folder:
RewriteRule ^en/(.*)$ /$1?lang=en [L,QSA]
RewriteRule ^de/(.*)$ /$1?lang=de [L,QSA]
RewriteRule ^es/(.*)$ /$1?lang=es [L,QSA]
RewriteRule ^ru/(.*)$ /$1?lang=ru [L,QSA]
RewriteRule ^(firstleague)/2013/([0-9]+)/?$ /liga.php?whatleague=$1&matchday=$2 [L,QSA]
Related
I am new to .htaccess
I am using apache rewrite to give access to virtual directories
following code works
RewriteRule ^maindir/subdir/prog1.php?$ prog1.php?schoolid=12 [L]
RewriteRule ^maindir/subdir/prog2.php?$ prog2.php?schoolid=12 [L]
RewriteRule ^maindir/subdir/prog3.php?$ prog3.php?schoolid=12 [L]
RewriteRule ^maindir/subdir/prog4.php?$ prog4.php?schoolid=12 [L]
RewriteRule ^maindir/subdir/prog5.php?$ prog5.php?schoolid=12 [L]
RewriteRule ^maindir/subdir/prog6.php?$ prog6.php?schoolid=12 [L]
but,
Instead of writing htacess code for each program prog1.php, prog2.php etc
can i use wild card...
Need your help
so that
https://abcd.com/maindir/subdir/anyprogram.com
will be actually executes
https://abcd.com/anyprogram.com
I tried (so as to use wild card in htaccess)
RewriteRule ^maindir/subdir/(.*)$ 1?schoolid=12 [R,L]
RewriteRule ^maindir/subdir/? https://abcd.com/?schoolid=12 [L,NE,R=301]
RewriteRule ^maindir/subdir/?$ $1?schoolid=12 [L,NE,R=301]
but failed
im quite new to rewrite rules.
I can manage with one variable and thats it.
I have webpage Where the rewriterule is:
RewriteCond %{HTTP_HOST} ^www\.someserver\.com$
RewriteRule ^/?$ "http\:\/\/someserver\.com\/" [R=301,L]
RewriteRule ^(\d+)*$ ./index.php?comp=$1
RewriteRule ^(\d+)*/$ ./index.php?comp=$1
And it all work fine as it should. But now as i want 1 more variable into URL
i cant get it to work.
Right now the $1 is only numbers.
someserver.com/1554886
But i want two variable.
someserver.com/1554886-SOMENAME-WHATEVER-WORD-AND-HOW-MANY
But it wont show.
i tried smth like this:
RewriteRule ^([^-]*)-([^-]*)$ ./index.php?comp=$1&string=$2 [L]
How do i get it to work?
Do i have to make some changes in the php side as well?
everything what comes after the number part of the URL is there only for
SEO, the number is Unique
You need one more rule to handle two parameters:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(someserver\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^(\d+)/?$ index.php?comp=$1 [L,QSA]
RewriteRule ^(\d+)-(.+)/?$ index.php?comp=$1&string=$2 [L,QSA]
my problem is that I want to get three simple rules working, but my knowledge is too little, to get them working together:
These are obvious:
RewriteRule ^login$ /login.php [L]
RewriteRule ^register$ /register.php [L]
domain.com/login and domain.com/register
Secondly, since i have only one page used for displaying data, i want its url to be as simple as posible, like:
RewriteRule ^(.*)$ /data.php?id=$1 [L]
which should be translated into:
domain.com/1a2s3d
As third, I want to be able to change url with activation code:
RewriteRule ^register/activate/([^/]+)$ /register.php?action=activate&code=$1 [L]
which finally should be translated into:
domain.com/register/activate/some-hash
I know just simply basics. And I cannot mix all of these three ideas into one single working htaccess file. With the second rule the server gives me 500 error, with third rule registration page works, but css file path is translated into domain.com/register/activate/theme/style.css instead of domain.com/theme/style.css
Any help would be appreciated.
Try just with that:
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^login$ /login.php [L]
RewriteRule ^register$ /register.php [L]
RewriteRule ^register/activate/([^/]+)$ /register.php?action=activate&code=$1 [L]
RewriteRule ^(.*)$ /data.php?id=$1 [L]
So I want to build a multilingual website.
At first I thought about setting language parameters through cookies, but Google says that it is not recomended. And I don't want to mess with Google because most of my visitors comes from search engines.
Google suggests subdomains likes lang.example.com or directories like example.com/lang
But I don't want to create multiple subdomains and directories in my host, so I will just use lang parameter in the URL like example.com/home?lang=de or example.com/about?lang=fr
And of course I want it to look like directories. I tried multiple htaccess configurations, but it either doesn't work at all or messes up my other rewrite rules with multiple parameters.
My old working htaccess looks like this:
RewriteRule ^about/?$ ?page=about [NC,QSA]
RewriteRule ^home/?$ ?page=home [NC,QSA]
RewriteRule ^browse/?$ ?page=browse [NC,QSA]
RewriteRule ^contact/?$ ?page=about&what=contact [NC,QSA]
RewriteRule ^message/?$ ?page=about&what=send [NC,QSA]
RewriteRule ^browse/([^/]+)$ ?page=make&make=$1 [NC,L,QSA]
RewriteRule ^browse/(.+)/(.+)/?$ ?page=browser&make=$1&ser=$2 [NC,L,QSA]
I tried adding
RewriteRule ^de/(.*)$ /$1?lang=de_DE [L,QSA]
and similar configurations, but it never works how I want.
Any ideas how to make it work?
Have your rules like this:
RewriteEngine On
# handle URIs with language parameters like /en/, /it/, /de/, /fi/ etc
RewriteRule ^([a-z]{2})/(about|home|browse)/?$ ?page=$2&lang=$1 [NC,QSA,L]
RewriteRule ^([a-z]{2})/contact/?$ ?page=about&what=contact&lang=$1 [L,NC,QSA]
RewriteRule ^([a-z]{2})/message/?$ ?page=about&what=send&lang=$1 [L,NC,QSA]
RewriteRule ^([a-z]{2})/browse/([^/]+)/?$ ?page=make&make=$2&lang=$1 [NC,L,QSA]
RewriteRule ^([a-z]{2})/browse/([^/]+)/([^/]+)/?$ ?page=browser&make=$2&ser=$3&lang=$1 [NC,L,QSA]
# defaulting to english
RewriteRule ^(about|home|browse)/?$ ?page=$1&lang=en [NC,QSA,L]
RewriteRule ^contact/?$ ?page=about&what=contact&lang=en [L,NC,QSA]
RewriteRule ^message/?$ ?page=about&what=send&lang=en [L,NC,QSA]
RewriteRule ^browse/([^/]+)/?$ ?page=make&make=$1&lang=en [NC,L,QSA]
RewriteRule ^browse/([^/]+)/([^/]+)/?$ ?page=browser&make=$1&ser=$2&lang=en [NC,L,QSA]
To have nice URLs I edited my .htacces file
domain.com/category/content
should be redirected to
domain.com/index.php?category=cat&content=cont
this works fine with this line
RewriteRule ^([^/]*)/([^/]*)$ /index.php?category=$1&content=$2 [L]
but
domain.com/category
should be redirected to
domain.com/index.php?category=cat
to display the contents of the whole category
I'm sure this is easy to solve but it is very confusing to me.
Use 2 rules:
RewriteRule ^([^/]+)/([^/]+)$ /index.php?category=$1&content=$2 [L]
RewriteCond %{REQUEST_URI} !/index.php
RewriteRule ^([^/]+)/?$ /index.php?category=$1 [L]