多语言网站mod重写问题
我在 mod 重写方面遇到问题,但在这里没有找到任何解决方案。问题是:
我有两种语言的网站,mod URL 应该如下所示:
/eng/contact
/srp/kontakt
/eng/news
/srp/vesti
/eng/event
/srp/najava
我的重写规则不起作用,因为我在 .htacess 中遇到这样的情况:
# news
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ news.php?lang=$1&pagename=$2 [NC,L]
# contact
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ contact.php?lang=$1&pagename=$2 [NC,L]
# event
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ event.php?lang=$1&pagename=$2 [NC,L]
我的问题是如何实现上述示例中页面的重写?
I have a problem with mod rewrite and did not find any solution here. Here is the problem:
I have website with two languages and mod URL should look something like this:
/eng/contact
/srp/kontakt
/eng/news
/srp/vesti
/eng/event
/srp/najava
Mine rewrite rule is not working because I have in .htacess situation like this:
# news
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ news.php?lang=$1&pagename=$2 [NC,L]
# contact
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ contact.php?lang=$1&pagename=$2 [NC,L]
# event
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ event.php?lang=$1&pagename=$2 [NC,L]
My question is how to achieve rewrite for pages in the above examples?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会使用:
然后通过使用一些简单的 switch-case-include 语句将 PHP 流从 index.php 路由到 news.php/contact.php 等:
这还将帮助您开发其他与路由相关的功能,从而简化 .htaccess 文件。这还可以轻松查找子页面的本机子页面名称,例如“en/contact”但“pl/kontakt”等。
我在几乎所有网站上都使用这种方法(例如 http://www.calculla.com/en/ascii2hex 和 http://www.calculla.com/pl/ascii2hex)。
I would use:
and then route the PHP flow from index.php to news.php/contact.php etc. by using some simple switch-case-include statement:
This will also help you develop other routing related features simplifying the .htaccess file. This also enables easy lookup for native subpages names of subpages like "en/contact" but "pl/kontakt" etc.
I use this approach on almost all my sites (e.g. http://www.calculla.com/en/ascii2hex and http://www.calculla.com/pl/ascii2hex).