.htaccess URL根据查询的第一部分重新路由到不同的文件夹

时间:2009-07-27 19:27:15

标签: apache .htaccess mod-rewrite

现在是我的.htaccess

rewriteengine on
rewritecond %{HTTP_HOST} ^www.example.com$ [OR]
rewritecond %{HTTP_HOST} ^example.com$
rewriterule ^index.php/? "http\:\/\/example\.com\/" [R=301,L] #4a397bb852bc9

将根目录中的所有请求发送到index.php 我需要做的是将所有请求从www.example.com/site2/发送到www.example.com/site2/index.php

我对正则表达式的理解总是没有达到这些好奇的规则和条件

谢谢,乔

1 个答案:

答案 0 :(得分:0)

您命名的规则会重定向任何请求,该网址路径以index.php开头,后跟可选的斜杠,主机名为www.example.comexample.com,状态码为301 http://example.com/

但是如果要将请求从一个目录重写到另一个目录,请尝试以下规则:

RewriteRule ^folder-1/?([^/].*)?$ folder-2/$1 [L]

修改回复您的评论:

RewriteCond $0 !=site2/index.php
RewriteRule ^site2/.* site/index.php [L]