gpt4 book ai didi

apache - Mod_Rewrite 将子域和目录设置为 GET 变量

转载 作者:行者123 更新时间:2023-12-01 12:41:45 24 4
gpt4 key购买 nike

我编写了一个我想要多语言的网站,应该可以通过子域访问不同的语言,例如 en.example.com、de.example.com 等等。

此外,我已经进行了重写,将“目录”设置为 GET 变量,将 example.com/name 更改为 example.com/index.php?page=name。

无论我尝试过什么,我都找不到将我需要使用的两个代码正确组合以解决这些各自问题的可能性。每个都有自己的作品,我只需要一个方法将两者结合起来,这样 en.example.com/name 就会被重写为 example.com/index.php?page=name&lang=en

我用什么目录获取变量

RewriteRule ^/?(\w*)/?$ index.php?page=$1 [L]

我在子域中找到的 GET 变量

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !index\.php
RewriteCond %{HTTP_HOST} ^(.+?)\.example\.com$
RewriteRule .* /index.php?lang=%1 [L]

最佳答案

你只需要结合你的 2 条规则

RewriteEngine On

RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.example\.com$
RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^(.*)$ /index.php?page=$1&lang=%1 [L]

关于apache - Mod_Rewrite 将子域和目录设置为 GET 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25582265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com