将子域重定向到相应的文件夹

时间:2016-02-08 22:37:56

标签: apache .htaccess redirect mod-rewrite

是否可以配置.htaccess,以便每次我想添加子域时,任何子域都会被重定向到相应的文件夹而无需编辑.htaccess文件?怎么样?

foo.domain.com -> /subdomains/foo
bar.domain.com -> /subdomains/bar

anything.domain.com/file.txt -> /subdomains/anything/file.txt

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以在站点根目录中使用此规则.htaccess:

DECLARE @PerLabelQuantity TABLE(Id int, Label varchar(10), Quantity int);
INSERT INTO @PerLabelQuantity 
VALUES (1, 'aaa', 10), (1, 'bbb', 20), (2, 'ccc', 20);

SELECT *
FROM @PerLabelQuantity

DECLARE @QuantityRequired TABLE(Id int, TotalQuantity int);
INSERT INTO @QuantityRequired
VALUES (1, 60), (2, 20);

SELECT *
FROM @QuantityRequired

-- MAKE A FAKE LABEL LET'S CALL IT [NULL] WITH THE AMOUNT THAT IS NOT LABELED
-- i.e. WITH THE REMAINING AMOUNT
-- Probably should be done by copying the original data and the following
-- into a temp table but this is just for proof of concept
INSERT INTO @PerLabelQuantity( Id, Label, Quantity )
SELECT q.ID, 
       NULL, 
       ISNULL(q.TotalQuantity - p.TotalQuantityLabeled, q.TotalQuantity)
FROM @QuantityRequired q
     LEFT JOIN (SELECT p.ID, SUM(Quantity) AS TotalQuantityLabeled 
                 FROM @PerLabelQuantity p 
                 GROUP BY p.Id) p ON 
          p.ID = q.ID
          AND q.TotalQuantity - p.TotalQuantityLabeled > 0

SELECT *
FROM @PerLabelQuantity p