.htaccess子域目录

时间:2017-05-26 17:18:52

标签: php apache .htaccess mod-rewrite

我的.htaccess代码是:

RewriteRule ^404\.php$ - [L]

Rewritecomnd %{HTTP_HOST} !^www\.example\.com
Rewritecomnd %{HTTP_HOST} ([^.]+)\.example\.com [NC]
RewriteRule ^/?$ /profile/index.php?name=%1 [L]

Rewritecomnd %{HTTP_HOST} !^www\.example\.com
Rewritecomnd %{HTTP_HOST} [^.]+\.example\.com [NC]
Rewritecomnd %{REQUEST_URI} ^/([^/]+)$
RewriteRule !^profile/ /profile/%1 [L]

让我告诉你这是做什么的:

  1. bob.example.com显示页面www.example.com/profile/index.php?name=bob
  2. bob.example.com/page1.php仅显示个人资料目录中的页面www.example.com/profile/page1.php
  3. 问题:

    问题是,如果我转到bob.example.com/directory/page.php,它会显示我的根目录的目录。我怎么能这样做呢 bob.example.com/directory/page.php显示www.example.com/profile/directory/page2.php

1 个答案:

答案 0 :(得分:1)

你的RewriteCond模式与uri /directory/page.php 不匹配。您需要从正则表达式中删除受限制的 / ,或者使用全能模式。

将您的上一次RewriteCond更改为:

 RewriteCond %{REQUEST_URI} ^/(.+)$