通配符子域设置

时间:2017-09-16 02:00:23

标签: .htaccess url-rewriting wildcard-subdomain

这适用于重写位于我的根文件夹中的 index.php 的所有请求,适用于example.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}

我正在尝试计算如何重写通配符子域。通配符应该预先添加到路径中。如何修改这些规则以完成以下网址方案。

example.com/1 / 等于 1.example.com

example.com/1/2 等于 1.example.com/2

example.com/1/2/3 等于 1.example.com/2/3

example.com/1/2/3/4 等于 1.example.com/2/3/4 < / p>

我已在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]

1 个答案:

答案 0 :(得分:1)

让我理解。您是否在询问如何设置,以便当用户导航到 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]

只需编辑指向您需要的链接!

相关问题