重写URL mod_rewrite的与学语言 [英] Rewriting URLs with mod_rewrite for languages

查看:206
本文介绍了重写URL mod_rewrite的与学语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些网址使用mod_rewrite为我的网站重写,但我想不通的常规前pressions。

下面是当前的URL可能看起来是这样的:结果
http://mydomain.com/zenphoto/pages/xyz?locale=en_US 结果
http://mydomain.com/zenphoto/pages/xyz?locale=de_DE

http://mydomain.com/zenphoto/gallery_1?locale=de_DE 结果
http://mydomain.com/zenphoto/gallery_n?locale=de_DE

XYZ 可能包含不同的字符串,例如法律关于

这就是我想使用的URL:结果
http://mydomain.com/zenphoto/de/pages/xyz 结果
http://mydomain.com/zenphoto/en/pages/xyz

http://mydomain.com/zenphoto/de/gallery_1 结果
http://mydomain.com/zenphoto/en/gallery_n

我要指出,只有连接应是可能的。任何其他字符串,应重新路由到

可能有人帮助我吗? : - )

谢谢,结果
罗伯特


解决方案

  RewriteEngine叙述上
重写规则^ zenPHOTO提供/页/([A-Z] +)\\区域=(ZH | DE)?_ [A-Z] {2} $ / zenPHOTO提供/ $ 2 /页/ $ 1
?重写规则^ zenPHOTO提供/图库_([0-9])\\区域=(ZH | DE)_ [A-Z] {2} $ / zenPHOTO提供/ $ 2 / $ gallery_ 1

对于第一个例子,我说:如果URL启动( ^ 的)与zenPHOTO提供/页/,然后有小写字母( + 的手段序列一个或多个,而 [AZ] 的意思),这是我的第一组,在[A,b,......,Y,Z]的一封信(有括号 - >这是一组),那么它的后面,然后用en或​​(的语言环境=?| 的手段或)德,这是我的第二组,那么它的后面跟着一个下划线(_)和两个大写字母,并没有什么后( $ 的意味着它是URL的结束)。
我写了一个空间,新的URL我想要的,我用的 $ n 的使用的 N 的-th组。
第二个URL是pretty一个人,第一个是真实的。

您之前有特殊字符喜欢用反斜杠,+,{},(,),[,],*,?。|如果你想使用一个在你的网址。

编辑:

如果你想避免无限循环,你应该添加标记的 [L] 的(L =姓)在每行的末尾。

I need some URL rewriting for my website using mod_rewrite but I can't figure out the regular expressions.

Here is what the current URLs may look like:
http://mydomain.com/zenphoto/pages/xyz?locale=en_US
http://mydomain.com/zenphoto/pages/xyz?locale=de_DE

http://mydomain.com/zenphoto/gallery_1?locale=de_DE
http://mydomain.com/zenphoto/gallery_n?locale=de_DE

xyz may contain different strings, e.g. legal, about, etc.

And that's how I'd like the URLs to be used:
http://mydomain.com/zenphoto/de/pages/xyz
http://mydomain.com/zenphoto/en/pages/xyz

http://mydomain.com/zenphoto/de/gallery_1
http://mydomain.com/zenphoto/en/gallery_n

I should mention that only de and en shall be possible. Any other strings shall be rerouted to de.

Could somebody help me please? :-)

Thanks,
Robert

解决方案

RewriteEngine on
RewriteRule ^zenphoto/pages/([a-z]+)\?locale=(en|de)_[A-Z]{2}$ /zenphoto/$2/pages/$1
RewriteRule ^zenphoto/gallery_([0-9])\?locale=(en|de)_[A-Z]{2}$ /zenphoto/$2/gallery_$1

For the first example, I say: "If the URL starts (^) with "zenphoto/pages/" then have a sequence of lowercase letters (+ means "one or more", and [a-z] means "a letter in [a, b, ..., y, z]"), which is my first group (there is parentheses -> it's a group). Then it's followed by "?locale=", then by "en" or (| means "or") "de", and this is my second group, then it's followed by an underscore ("_") and two uppercase letters, and there is nothing after ($ means it's the end of the URL)". I write a space, and the new URL I want, and I use $n to use the n-th group. The second URL is the 'pretty one', and the first is the real.

You have to use backslashes before special chars like ?,+,{,},(,),[,],*,.,| if you want to use one in your URL.

Edit:

If you want to avoid infinite loops, you should add the flag [L] (L = Last) at the end of each line.

这篇关于重写URL mod_rewrite的与学语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆