我正在尝试将我的网站从http://www.masterflooringtampa.com重定向到自动转到http://www.masterflooringtampa.com/en/。我已经能够改变我的htaccess来做我需要的一切,除此之外。请记住,我使用RewriteRule ^ en /?$ index.php?lang_id = 1 [NC,QSA,L]来指向正确的php处理程序。任何htaccess专家都能指出正确的方向吗?此外,如果你有一个快捷方式或方法来设置一个公式来清理脚本(我只是做蛮力,每个url /链接在自己的方法,但有效但不是很优雅)我将不胜感激。
<IfModule mod_expires.c>
# defaults to the english site
RewriteRule ^en/?$ index.php?lang_id=1 [NC,QSA,L]
RewriteRule ^es/?$ index.php?lang_id=2 [NC,QSA,L]
RewriteRule ^en/products/?$ products.php?lang_id=1 [NC,QSA,L]
RewriteRule ^es/products/?$ products.php?lang_id=2 [NC,QSA,L]
RewriteRule ^en/services/?$ services.php?lang_id=1 [NC,QSA,L]
RewriteRule ^es/services/?$ services.php?lang_id=2 [NC,QSA,L]
RewriteRule ^en/about/?$ about.php?lang_id=1 [NC,QSA,L]
RewriteRule ^es/about/?$ about.php?lang_id=2 [NC,QSA,L]
RewriteRule ^en/contact/?$ contact.php?lang_id=1 [NC,QSA,L]
RewriteRule ^es/contact/?$ contact.php?lang_id=2 [NC,QSA,L]
RewriteRule ^en/floors/hardwood/?$ floors/hardwood.php?lang_id=1 [NC,QSA,L]
RewriteRule ^es/floors/hardwood/?$ floors/hardwood.php?lang_id=2 [NC,QSA,L]
RewriteRule ^en/floors/carpet/?$ floors/carpet.php?lang_id=1 [NC,QSA,L]
RewriteRule ^es/floors/carpet/?$ floors/carpet.php?lang_id=2 [NC,QSA,L]
RewriteRule ^en/floors/laminate/?$ floors/laminate.php?lang_id=1 [NC,QSA,L]
RewriteRule ^es/floors/laminate/?$ floors/laminate.php?lang_id=2 [NC,QSA,L]
RewriteRule ^en/floors/tile/?$ floors/tile.php?lang_id=1 [NC,QSA,L]
RewriteRule ^es/floors/tile/?$ floors/tile.php?lang_id=2 [NC,QSA,L]
RewriteRule ^en/floors/vinyl/?$ floors/vinyl.php?lang_id=1 [NC,QSA,L]
RewriteRule ^es/floors/vinyl/?$ floors/vinyl.php?lang_id=2 [NC,QSA,L]
</IfModule>
答案 0 :(得分:1)
如果我理解你所要求的内容,那么您的网站似乎正常运作
要清理代码,您可以使用此
替换代码<IfModule mod_expires.c>
# defaults to the english site
RewriteRule ^en/?$ index.php?lang_id=1 [NC,QSA,L]
RewriteRule ^es/?$ index.php?lang_id=2 [NC,QSA,L]
RewriteRule ^(en)/([a-zA-Z])/?$ $2.php?lang_id=1 [NC,QSA,L]
RewriteRule ^(es)/([a-zA-Z])/?$ $2.php?lang_id=2 [NC,QSA,L]
RewriteRule ^(en)/([a-zA-Z])/([a-zA-Z])/?$ $2/$3.php?lang_id=1[NC,QSA,L]
RewriteRule ^(es)/([a-zA-Z])/([a-zA-Z])/?$ $2/$3.php?lang_id=2[NC,QSA,L]
</IfModule>