我有一个多语言网站和。 Htaccess,显示所有页面。
我想重定向(使用代码301)询问RewriteEngine
。例如:
site.com?lang=ru => site.com (remove `lang=ru` - Russian only)
site.com/news.html?lang=ru => site.com/news.html
site.com/home.html => site.com (remove `home.html` - only on the main page)
site.com/home.html?lang=ua => site.com/?lang=ua
site.com/rev.html?lang=ua&start=0 => site.com/rev.html?lang=ua (If start = 0, then remove `start=0`)
site.com/rev.html?lang=ua&start=27 => site.com/rev.html?start=27&lang=ua (should be conversely)
and so on many ...
我对重定向的经验很少。你可以帮助我。如何准备Apache的htaccess文件以满足这个标准?怎么办?
提前致谢
答案 0 :(得分:4)
删除lang=ru
RewriteCond %{QUERY_STRING} ^(.*)&?lang=ru(.*)$
RewriteRule ^(.*)$ /$1?%1%2 [L,R=301]
删除home.html
RewriteRule ^home.html$ / [L,R=301]
删除start=0
RewriteCond %{QUERY_STRING} ^(.*)&?start=0(.*)$
RewriteRule ^(.*)$ /$1?%1%2 [L,R=301]
交换start=##
和lang=##
RewriteCond %{QUERY_STRING} ^(.*)lang=(.+)&start=([0-9]+)(.*)$
RewriteRule ^(.*)$ /$1?%1start=%3&lang=%2%4 [L,R=301]