Problem in interpreting Rewriterule parameters in htaccess - mod-rewrite

I have a site in Serbian and English.
URL-friendly link determine which language will be displayed. The language specifies the first parameter after the domain name (/sr/ or /en/).
For text in serbian language, this is a link:
www.mysite.com/sr/proizvodi/product-name/25
and for english, this is a link:
www.mysite.com/en/products/product-name/25
My .htaccess file has commands:
RewriteRule ^sr/proizvodi/(.*)/([0-9]+)$ details.php?id=$2&lang=sr [L]
RewriteRule ^en/products/(.*)/([0-9]+)$ details.php?id=$2&lang=en [L]
The problem is that the site launches the English version if pattern "en" also appears in the product name. For exampl:
www.mysite.com/sr/proizvodi/vis**en**am**en**ska cetka/129
Does anyone have an idea to solve this problem?

Related

Two parametrs in mod_rewrite rule

I have problem with mod_rewrite rule.
I'm trying to get adress:
www.site.com/en/page.html
from url
index.php?page=page&lang=en
I've tried a couple of hours and I can not get ... Unfortunately, I do not know at all mod_rewrite ...
Can someone a guiding me to a solution?
-
Peter
First, make sure mod_rewrite is enabled in your Apache configuration file.
Also, make sure htaccess files are allowed (AllowOverride All for your document root folder).
Then, put this code in your htaccess (which has to be in document root folder)
RewriteEngine On
RewriteRule ^([a-z]{2})/([^/]+)\.html$ /index.php?page=$2&lang=$1 [L]
This rule allows you to reach any language/page, for instance:
http://domain.com/en/page.html --> /index.php?page=page&lang=en
http://domain.com/fr/something.html --> /index.php?page=something&lang=fr
If you want to restrict lang parameter:
For english only
RewriteEngine On
RewriteRule ^en/([^/]+)\.html$ /index.php?page=$1&lang=en [L]
For english and french (as an example)
RewriteEngine On
RewriteRule ^(en|fr)/([^/]+)\.html$ /index.php?page=$2&lang=$1 [L]
Thank you for your help - exactly is what I meant.
Roughly already beginning to understand what's going on...
From the documentation at hand I can handle it :)
-
Peter

301 redirect in .htacces doesnt work:( Redesigned a site but cant get the old url's to link to new ones

I redesigned this website, and tried to create a 301 redirect to redirect the old links to the new ones in order to save the existing google pagerank. I am using joomla for my site.
Example of a link i tried:
Old link: frutaplantaonline.nl/cgi-bin/index.pl?n=823&txt=privacy_policy
New link: frutaplantaonline.nl/privacy-policy
I tried:
Redirect 301 /cgi-bin/index.pl?n=823&txt=privacy_policy http://frutaplantaonline.nl/privacy-policy
RewriteRule ^/?cgi-bin/index.pl?n=823&txt=privacy_policy/?$ http://frutaplantaonline.nl/privacy-policy [L,R=301]
All the links have the cgi-bin/index.pl in it, if i remove the dot in index.pl i can redirect the site.
Have been searching for hours and hours but found no solution, I'd appreciate if someone can help me out!
Redirect directive in your case is uselsess as it works only on paths (i.e. /cgi-bin/index.pl).
You need to use RewriteRule directive and accompany it with RewriteCond to match against query string. From the official documentation:
If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.
So in your case something like this might do:
RewriteCond %{QUERY_STRING} n=823&txt=privacy_policy
RewriteRule ^/cgi-bin/index.pl$ http://frutaplantaonline.nl/privacy-policy [R=301,L]

How to 301 alternative language sites to english?

My client has a website that has english, german, spanish and french sites. They are just simple folder structures on the server inside the public_html directory eg. /de, /fr, /en and /es
They have decided to remove the other languages and only have english but i have quite a few pages that need 301 redirecting.
I already use a mod_rewrite for doing pretty URLs throughout.
What would be the best way to redirect the alt language pages to the english pages without disrupting the pretty URLs?
eg. fr/news/news-article -> en/news/news-article
I already have:
RewriteRule ^([^/\.]+)/news?$ $1/news.php [L]
Add this RewriteRule line on top of all other Rewrite rules in your .htaccess:
RewriteRule ^(?:de|fr|es)(/.*|)$ /en$1 [L,R=301,NC]
This will redirect (with R=301) every /fr/bla/bla or /de/bla/bla or /es/bla/bla to /en/bla/bla

ModRewrite .htaccess / SEO URLs syntax

I am trying to re-use some .htaccess code on a new site/server and it doesn't work correctly. I'm not an expert with URL rewriting so would appreciate it if anyone can see if my syntax is incorrect or if there is something else I need to check server side.
I am using the following code:
Options +FollowSymLinks
RewriteEngine on
# News Pages
RewriteRule ^news/$ /news.php
RewriteRule ^news/(.*?)/$ /news.php?article=$1
It works for the 1st level, /news/ but /news/article-1/ just loads the /news/ (news.php) overview page. /news.php?article=article-1 works correctly.
Server is running Apache 2.2.9 and PHP is in CGI mode.
Try it such way:
RewriteRule ^news/(.*?)/?$ /news.php?article=$1 [L]
RewriteRule ^news/?$ /news.php [L]
[L] in the end of instruction stops server cheacking of other instructions, if current one match.
So you write more specific ahead of more general.
If your rules work correctly being the only one in the .htaccess, then such organisation of them can help.
/? - this means that / at the end can absent or present

mod_rewrite one domain to another while preserving URL for bilingual site

I have two domains: myenglishdomain.com and myfrenchdomain.com. They both point to the same folder on my server (the english domain). The way I've structured the server is that the english content is at myenglishdomain.com/en and my french content is at myenglishdomain.com/fr (note: my english domain, not the french one).
when a user types in myfrenchdomain.com/content I'd like the URL to still read myfrenchdomain.com/content, and yet point to myenglishdomain.com/fr/content
is this possible? What would be the rule(s) to make this happen?
RewriteCond %{HTTP_HOST} ^myfrenchdomain.com
RewriteRule ^/content/(.*) http://myenglishdomain.com/fr/content/$1 [P]

Resources