Forum Moderators: phranque
I'm trying to rewrite fr/es/en language directories and add them to the query string (as &langauge=fr or?language=fr):
mysite.com/fr/index.php
=> mysite.com/catalog/index.php?language=fr
and
mysite.com/fr/index.php?cPath=22
=> mysite.com/catalog/index.php?cPath=22&language=fr
This is how far I've gotten so far:
RewriteEngine on
RewriteBase /
RewriteRule ^([en¦es¦fr]+)/(.*)$ /catalog/$2?language=$1 [L]
Can someone point me to some sample code / documentation on this specific situation or maybe share some advice on where I'm not getting this right.
The pipe character within a group is interpreted literally, so you've told the regex parser to match any URL-path starting with one or more characters equal to 'e', 'n', '¦', 's', 'f', or 'r', followed by a slash, followed by anything or nothing.
In addition, specifying a new query string will replace any existing character string in the client request by default. In order to retain your 'cPath' name/value pair, you'll need to use [QSA] -- the Query String Append flag, to append the new 'language' name/value pair to the existing 'cPath' name/value pair if present.
So, you may have better luck with something like this:
RewriteRule ^(en¦es¦fr)/(.*)$ /catalog/$2?language=$1 [QSA,L]
There may be other problems, but this should eliminate at least two of them.
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
I have had the same problem that you had and I have solved it with this code:
DirectoryIndex index.html index.htm index.php
ErrorDocument 404 /404.php
RewriteEngine On
RewriteBase /
RewriteRule ^(it¦en)/file/site/image/(menu¦titoli)/(.+)$ file/site/image/$1/$2/$3 [L,NC]
RewriteRule ^(it¦en)/(.+)$ $2?l=$1 [QSA,NC,L]
RewriteRule ^(it¦en)/$ index.php?l=$1 [NC,L]
I still have a problem: i would like that if you type [domain.it...] you will receive a 404 error.
In other words i need a Rules that sounds like this:
if (!ereg('/it/',URL) &&!ereg('/en/',URL) {
goTo(myErrorPage.php);
}
If URL don't contains '/it/' and don't contains '/en/' web server must show a determinate page.
I hope you can understand me..
Thanks, Bye.
superpelo, I am sorry but I don't know how to do what you are requestion. I think I read in here somewhere that you can set up a redirect to something that doesn't exist, as that will trigger your 404 rule, or you can do as I have done a number of times - create a 404 http status code with you php script: header("HTTP/1.1 404 Not Found");
superpelo,
It's not entirely clear *where* in the URL the "it" or "en" should be found, but based on your existing rules, I think you're looking for something like this:
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /(it¦en)
RewriteRule .* /path-to-file-that-does-not-exist.xyz [L]
However, it will rewrite all other requests without "it" or "en" at the beginning to a filepath that is invalid -- it does not exist. So, this triggers your server's 404 response handler.
Replace the broken pipe "¦" character with a solid pipe character before use; Posting on this forum modifies the pipe characters.
Jim
[edited by: jdMorgan at 3:40 pm (utc) on June 30, 2007]