尽管我确信这是一件非常简单的事情,但我一直在努力地解决这一问题。
我有一个具有简单域的网站(即example.com),并且设置了htaccess文件,以便example.com/contact将其重写为example.com/contact.php,如下所示:
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^about(\/?)$ about.php
RewriteRule ^contact((-?us)?)(\/?)$ contact.php
RewriteRule ^register(\/?)$ register.php
当用户访问en.example.com或fr.example.com等(对于语言)时,我追求的是什么,它会拍打?lang = fr或&lang = fr(?或&取决于如果还有其他网址参数)
我尝试过这样的事情:
RewriteCond %{HTTP_HOST} ^(\w{2})\.example\.com$
RewriteRule ^about(\/?)$ about.php?lang=%1
RewriteRule ^contact((-?us)?)(\/?)$ contact.php?lang=%1
RewriteRule ^register(\/?)$ register.php?lang=%1
我使用:https://htaccess.madewithlove.be
进行了测试以上方法工作正常,将“ en.example.com/about”放入“ en.example.com/about.php?lang=en”,但是如果我尝试“ en.example.com/contact”它会返回“ en.example.com/contact.php?lang=%1”。
我确实尝试查找一些通用示例,但似乎没有一个能完全满足我的要求,感谢您的帮助:)