如何在 .htaccess 中为多语言网站重写 url
how to rewrite url in .htaccess for a multilingual website
正在尝试设置多语言网站,但在重写 URL 时遇到问题。
当前的 .htaccess 不再需要指定 .php 扩展名,如下所示:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .php [NC,L]
所以 gettext 已经设置并翻译了一些语言,url 切换语言如下:
mysite.com/news?locale=en_US
mysite.com/news?page=2&locale=zh_TW
mysite.com/press?page=3&locale=it_IT
然而我的最终目标是这样使用:
mysite.com/en/news <= translated => mysite.com/news?locale=en
mysite.com/zh_tw/news/2 <= translated => mysite.com/news?page=2&locale=zh_TW
mysite.com/it/press/3 <= translated => mysite.com/press?page=3&locale=it
谁能告诉我正确的方向,谢谢。
RewriteRule ^([^/]+)/([^/]+)$ ?locale= [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+) ?page=&locale= [QSA,L]
正在尝试设置多语言网站,但在重写 URL 时遇到问题。
当前的 .htaccess 不再需要指定 .php 扩展名,如下所示:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .php [NC,L]
所以 gettext 已经设置并翻译了一些语言,url 切换语言如下:
mysite.com/news?locale=en_US
mysite.com/news?page=2&locale=zh_TW
mysite.com/press?page=3&locale=it_IT
然而我的最终目标是这样使用:
mysite.com/en/news <= translated => mysite.com/news?locale=en
mysite.com/zh_tw/news/2 <= translated => mysite.com/news?page=2&locale=zh_TW
mysite.com/it/press/3 <= translated => mysite.com/press?page=3&locale=it
谁能告诉我正确的方向,谢谢。
RewriteRule ^([^/]+)/([^/]+)$ ?locale= [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+) ?page=&locale= [QSA,L]