Alain Roger wrote:
In your regular expression above, the parts "(*)" probably do not mean what you think they do. As written, they mean "the character '(', 0 or more times". You probably want "(.*)" instead, which means "any character, 0 or more times". The first part of the RewriteRule is a "regular expression", which is different from a "file wildcard".Hi, i would like to redirect all requests as following: http://www.mywebsite.com/en/logon/index.php => http://www.mywebsite.com/logon/index.php?lang=en http://www.mywebsite.com/fr/logon/logon.php => http://www.mywebsite.com/logon/logon.php?lang=fr http://www.mywebsite.com/en/logon/hello.php => http://www.mywebsite.com/logon/hello.php?lang=en http://www.mywebsite.com/en/welcome/index.php => http://www.mywebsite.com/welcome/index.php?lang=en so i tried to do the following rule but without success. RewriteRule ^(sk|en|fr)/(*)/(*)$ $2/$3?lang=$1 [L] so how can i write a rule that will proceed: - whatever the folder is: logon, welcome, .... - whatever file it is: index.php (or nothing), hello.php,....
Try this :RewriteRule ^/(sk|en|fr)/(welcome|logon)/(hello|index)\.php$ /$2/$3.php?lang=$1 [L]
You could do this : RewriteRule ^/(sk|en|fr)/([^/]+)/(.*)$ /$2/$3?lang=$1 [L]but that matches more than just your examples above, so it could generate URLs that you do not want, for example it would also do
http://www.mywebsite.com/en/anything/something.php ==> http://www.mywebsite.com/anything/something.php?lang=enIt is generally better to "limit" your rule to what you think the incoming URLs might reasonably be, rather than make a very general rewrite rule that will rewrite even nonsense URLs. This could also be dangerous, leading to executing things you do not really want to make available.
Last thing : for the last element of the URL, which you say can be "nothing" or index.php or hello.php, the "nothing" case is a bit of a problem. Can you give an example of what you would want to generate in case the incoming URL is, e.g.
http://www.mywebsite.com/en/anything ==> http://www.mywebsite.com/anything?lang=en does not seem to make sense. --------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project. See <URL:http://httpd.apache.org/userslist.html> for more info. To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx " from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx