0

如果 URL 请求中未指定子文件夹,我需要将我的域重定向到子文件夹。

例如。

a) 如果请求来自“domian.com”或“www.domain.com”,我想将其重定向到“www.domain.com/page”。

b) 但是,如果请求来自“domain.com/page2”或“www.domain.com/page2”,我不希望将请求重定向到“www.domain.com/page”。

我一直在虚拟主机中尝试一些排列,但没有运气。下面是我的代码:

<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com

<Directory />
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    <IfModule mod_rewrite.c>
      Options +FollowSymLinks
      Options +Indexes
      RewriteEngine On
      RewriteBase /
      RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
      RewriteCond %{REQUEST_URI} !^/$1
      RewriteRule ^(.*)$ /Page [L]
    </IfModule>
</Directory>

ProxyPreserveHost On
ProxyPass         /  http://www.domain.com:8080/
ProxyPassReverse  /  http://www.domain.com:8080/
</VirtualHost>

任何指针都会有所帮助。

4

2 回答 2

1

你可以试试这个:

  RewriteEngine On
  RewriteBase /
  RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com [NC]
  RewriteCond %{REQUEST_URI} ^$   [NC]
  RewriteRule .* /Page [L]
于 2013-03-27T08:13:59.420 回答
0

排除每个请求,因此从不使用。RewriteCond%{REQUEST_URI} !^/$1RewriteRule

如果您只想重写根目录,请改用特定的正则表达式 ^/$。您还必须将规则包装在适当的 中<Directory>,因为包含的所有内容都适用于文件系统目录,而不是URL 路径

<Directory /path/to/documentroot>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
    RewriteRule ^$ /Page [L]
</Directory>
于 2013-03-27T08:37:52.220 回答