通配符子域设置

Wildcard Sub-Domain Setup

这适用于将所有请求重写到位于我的根文件夹中的 index.php,例如。com/1/2/3/4/5/...

DirectoryIndex index.php
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ / [L]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.mallzones\.com$
RewriteRule (.*) /%{REQUEST_URI}

我也在想办法重写通配符子域。通配符应该放在路径的前面。如何修改这些规则以完成以下 url 方案。

例子。com/1/ 等于 1.example.com

例子。com/1/2 等于 1.example.com/2

示例。com/1/2/3 等于 1.example。 com/2/3

例子。com/1/2/3/4 等于 1.example.com/2/3/4

我已经在我的 DNS 区域中创建了 A 记录。接下来我该做什么?

答案:感谢 @CRIMSON 501

DirectoryIndex index.php
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ / [L]

让我明白。您是在问如何做到这一点,以便当用户导航到 example.com/1/ 时,他们会被重新路由到 1.example.com?

<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).example.com [NC]
RewriteRule (.*) http://example.com/ [L]
</IfModule>

要进行静默重定向,最后一行应为:

RewriteRule (.*) /index.php/or/whatever/you/need [L]

只需编辑您需要的链接即可!