.htaccess 获取变量作为子域
.htaccess Get variable as subdomain
我有一个正在手动翻译的网站。普通版为英文,翻译版为西班牙文。
翻译版本可通过 http://example.com/file.php?language=es 访问(es 代表西班牙语)
我希望域后的 URL 不会因翻译的变化而改变,所以我尝试使用 http://es.example.com/ 代替。
这是我的 htaccess 的当前状态:
RewriteCond %{HTTP_HOST} !^example\.site$
RewriteRule home/$ /index.php [L,QSA]
RewriteRule contact-us/$ /contact-us.php [L,QSA]
RewriteRule our-location/$ /our-location.php [L,QSA]
RewriteRule gallery/$ /gallery.php [L,QSA]
RewriteRule (.*)/$ /user.php?display_name= [L,QSA]
RewriteCond %{HTTP_HOST} !^es\.example\.site$
RewriteRule home/$ /index.php?language=es [L,QSA]
RewriteRule contact-us/$ /contact-us.php?language=es [L,QSA]
RewriteRule our-location/$ /our-location.php?language=es [L,QSA]
RewriteRule gallery/$ /gallery.php?language=es [L,QSA]
RewriteRule (.*)/$ /user.php?language=es&display_name= [L,QSA]
!^example.site$ 下的第一组规则都覆盖了 !^es.example.site$ 下的规则,所以当我访问带有或不带有 [=28= 的页面时] 子域,我正在获取英文版本。如果我将子域规则(和重写条件)置于非子域规则之上,那么会发生同样的事情,除了网站只翻译成西班牙语。
如有任何帮助,我们将不胜感激。
编辑:
固定规则,感谢@hjpotter92的帮助
RewriteRule ^home/?$ /index.php [NC,QSA,S=3]
RewriteRule ^(contact-us|our-location|gallery)/?$ /.php [NC,QSA,S=2]
RewriteRule ^(?!user\.php).*/$ /user.php?display_name=[=11=] [NC,QSA]
RewriteCond %{HTTP_HOST} ^es\.example\.site$ [NC]
RewriteCond %{QUERY_STRING} !language=es [NC]
RewriteRule ^.*$ /[=11=]?language=es [L,QSA]
您可能正在努力实现这一目标:
RewriteEngine On
RewriteRule ^home/?$ /index.php [NC,QSA,S=3]
RewriteRule ^(contact-us|our-location|gallery)/?$ /.php [NC,QSA,S=2]
RewriteRule ^(?!user\.php).*/$ /user.php?display_name=[=10=] [NC,QSA]
RewriteCond %{HTTP_HOST} ^es\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} !language=es [NC]
RewriteRule ^.*$ /[=10=]?language=es [L,QSA]
我有一个正在手动翻译的网站。普通版为英文,翻译版为西班牙文。
翻译版本可通过 http://example.com/file.php?language=es 访问(es 代表西班牙语) 我希望域后的 URL 不会因翻译的变化而改变,所以我尝试使用 http://es.example.com/ 代替。
这是我的 htaccess 的当前状态:
RewriteCond %{HTTP_HOST} !^example\.site$
RewriteRule home/$ /index.php [L,QSA]
RewriteRule contact-us/$ /contact-us.php [L,QSA]
RewriteRule our-location/$ /our-location.php [L,QSA]
RewriteRule gallery/$ /gallery.php [L,QSA]
RewriteRule (.*)/$ /user.php?display_name= [L,QSA]
RewriteCond %{HTTP_HOST} !^es\.example\.site$
RewriteRule home/$ /index.php?language=es [L,QSA]
RewriteRule contact-us/$ /contact-us.php?language=es [L,QSA]
RewriteRule our-location/$ /our-location.php?language=es [L,QSA]
RewriteRule gallery/$ /gallery.php?language=es [L,QSA]
RewriteRule (.*)/$ /user.php?language=es&display_name= [L,QSA]
!^example.site$ 下的第一组规则都覆盖了 !^es.example.site$ 下的规则,所以当我访问带有或不带有 [=28= 的页面时] 子域,我正在获取英文版本。如果我将子域规则(和重写条件)置于非子域规则之上,那么会发生同样的事情,除了网站只翻译成西班牙语。
如有任何帮助,我们将不胜感激。
编辑:
固定规则,感谢@hjpotter92的帮助
RewriteRule ^home/?$ /index.php [NC,QSA,S=3]
RewriteRule ^(contact-us|our-location|gallery)/?$ /.php [NC,QSA,S=2]
RewriteRule ^(?!user\.php).*/$ /user.php?display_name=[=11=] [NC,QSA]
RewriteCond %{HTTP_HOST} ^es\.example\.site$ [NC]
RewriteCond %{QUERY_STRING} !language=es [NC]
RewriteRule ^.*$ /[=11=]?language=es [L,QSA]
您可能正在努力实现这一目标:
RewriteEngine On
RewriteRule ^home/?$ /index.php [NC,QSA,S=3]
RewriteRule ^(contact-us|our-location|gallery)/?$ /.php [NC,QSA,S=2]
RewriteRule ^(?!user\.php).*/$ /user.php?display_name=[=10=] [NC,QSA]
RewriteCond %{HTTP_HOST} ^es\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} !language=es [NC]
RewriteRule ^.*$ /[=10=]?language=es [L,QSA]