使用 Apache 处理通配符子域,不包括 www,包括 SEF

发布于 2024-08-06 18:41:09 字数 545 浏览 7 评论 0原文

处理通配符子域的问题有一个答案,但它不能满足我的所有需求。我需要执行所有这些操作,假设域是 example.com

  1. 如果给定的域是 www.example.com 它应该 301 重定向到example.com,因为我不想有重复的内容,这会在搜索引擎中产生问题。

  2. 如果域名是anythingelse.example.com,它应该默默地重定向到example.com,以便软件可以获取所请求的子域并采取相应的行动。

  3. 此外,域名后面不引用实际文件或目录的任何规范都应重定向到index.php(软件将再次弄清楚这一切的含义)。因此,anything.example.com/some/search/engine/Friendly/specation 应重定向到 example.com/index.php

我可以让其中的一部分发挥作用,但还没有实现整个目标。有什么优惠!

There is an answer to the question of handling wild card subdomains, but it does not meet all my needs. I need to do all of these, supposing for example that the domain is example.com:

  1. If the domain given is www.example.com it should 301 redirect to example.com because I do not want to have duplicate content that will create problems in search engines.

  2. If the domain is anythingelse.example.com it should silently redirect to example.com so that software can pick up what subdomain was requested and act accordingly.

  3. In addition, any specification after the domain name that does not refer to an actual file or directory should be redirected to index.php (again the software will figure out what it all meant). So anything.example.com/some/search/engine/friendly/specification should redirect to example.com/index.php.

I can get parts of this to work, but have yet to achieve the whole thing. Any offers!

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

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

发布评论

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

评论(1

我最亲爱的 2024-08-13 18:41:09

尝试这些规则:

# 1. rule
RewriteCond %{HTTP_HOST} =www.example.com
RewriteCond %{HTTPS} ^on(s)|
RewriteRule ^ http%1://example.com%{REQUEST_URI} [L,R=301]

# 2. rule
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteRule ^ /absolute/filesystem/path/to/example.com%{REQUEST_FILENAME} [L]

# 3. rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

Try these rules:

# 1. rule
RewriteCond %{HTTP_HOST} =www.example.com
RewriteCond %{HTTPS} ^on(s)|
RewriteRule ^ http%1://example.com%{REQUEST_URI} [L,R=301]

# 2. rule
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteRule ^ /absolute/filesystem/path/to/example.com%{REQUEST_FILENAME} [L]

# 3. rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文