RewriteEngine:index.php的子域,怎么样?

发布于 2024-09-07 20:06:29 字数 1000 浏览 0 评论 0 原文

几天后,我询问有关将动态目录重定向到index.php的问题,我得到了这段运行完美的代码(这是我在.htaccess中唯一的代码):

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*) index.php

这会翻译像 http://mydomain.example/dynamicdir/http://mydomain.example/index.php

现在我想翻译 http://dynamicdir.mydomain.examplehttp://mydomain.example/index.php?dir=dynamicdir

从我在互联网上找到的示例中,我尝试添加这一行:

RewriteRule ^(.*)\.mydomain\.example index.php?dir=$1

但它不起作用。我没有足够的 mod-rewrite 经验来判断缺少或错误的内容。您能帮我找到一种保留动态目录翻译并添加捕获所有子域规则的方法吗?

问候!

Days later I asked about redirecting dynamic directories to index.php, and I got this code that works perfect (it's the only code I have in .htaccess):

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*) index.php

This translates urls like http://mydomain.example/dynamicdir/ to http://mydomain.example/index.php

Now I want to translate subdomains like http://dynamicdir.mydomain.example to http://mydomain.example/index.php?dir=dynamicdir

From examples I found in Internet I tried adding this line:

RewriteRule ^(.*)\.mydomain\.example index.php?dir=$1

But it doesn't work. I don't have enough experience with mod-rewrite to tell what's missing or wrong. Could you please help me to find a way to keep the dynamic directory translation, and add the catch-all subdomain rule?

Regards!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北城孤痞 2024-09-14 20:06:29

mod_rewrite 规则使用请求路径,该路径相对于虚拟主机。尝试为每个虚拟主机设置不同的重写规则,但将它们的文档放在同一目录中。

The mod_rewrite rules use the request path, which is relative to the virtual host. Try having different rewrite rules for each virtual host, but placing their documents in the same directory.

马蹄踏│碎落叶 2024-09-14 20:06:29

使用 RewriteRule 你只能测试URL 路径。对于主机名,您需要在 %{HTTP_HOST} ="nofollow noreferrer">RewriteCond

RewriteCond %{HTTP_HOST} ^(.+)\.example\.example$
RewriteRule ^ index.php?dir=%1

With RewriteRule you can only test the URL path. For the host name, you need to use %{HTTP_HOST} in a RewriteCond:

RewriteCond %{HTTP_HOST} ^(.+)\.example\.example$
RewriteRule ^ index.php?dir=%1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文