如果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>任何提示都会很有帮助。
发布于 2013-03-27 16:13:59
您可以尝试执行以下操作:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com [NC]
RewriteCond %{REQUEST_URI} ^$ [NC]
RewriteRule .* /Page [L]发布于 2013-03-27 16:37:52
RewriteCond%{REQUEST_URI} !^/$1会排除每个请求,因此永远不会使用RewriteRule。
如果您只想重写根目录,请改用特定的regular expression ^/$。您还必须将规则包装在适当的<Directory>中,因为包含的所有内容都适用于文件系统目录,而不是URL路径
<Directory /path/to/documentroot>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^$ /Page [L]
</Directory>https://stackoverflow.com/questions/15654032
复制相似问题