0

如何使用 RewriteRule 将网站 http 根目录指向子文件夹?

我总是使用下面的规则,但现在升级到最新的 wamp 服务器后,它不再工作了。为什么?

RewriteRule ^/?$  local/applications/bin/oldsite/index.htm [L,QSA]

例如,我想指出,

http://mysite.com/http://mysite.com/local/applications/bin/oldsite/index.htm

或者在 localhost wamp 服务器中,应该是这样的,

http://localhost/mysite/http://localhost/mysite/local/applications/bin/oldsite/index.htm

有任何想法吗?

并且,

http://localhost/mysite/contact.htmhttp://localhost/mysite/local/applications/bin/oldsite/contact.htm

http://localhost/mysite/about.htmhttp://localhost/mysite/local/applications/bin/oldsite/about.htm

编辑

我设法使用以下规则将其他页面指向特定位置,

RewriteRule ^([a-zA-Z0-9\-]+)\.htm/?$  local/applications/bin/oldsite/$1.htm [L,QSA]

但我仍然无法指出

http://localhost/mysite/http://localhost/mysite/local/applications/bin/oldsite/index.htm

4

3 回答 3

1

更新

你可以试试这个:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

#### localhost sets of rules
# No target file, go to index.php
RewriteCond %{HTTP_HOST}   localhost     [NC]
RewriteCond %{REQUEST_URI} ^/mysite/?$
RewriteCond %{REQUEST_URI} !index\.htm   [NC]
RewriteRule  .  mysite/local/applications/bin/oldsite/index.htm  [R=301,L]

# Target file, go to file
RewriteCond %{HTTP_HOST}     localhost     [NC]
RewriteCond %{REQUEST_URI}  ^/mysite/([^\.]+)\.htm [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule  .  mysite/local/applications/bin/oldsite/%1.htm  [R=301,L]

#### Live site set of rules
RewriteCond %{HTTP_HOST}   (?:www\.)?mysite\.com  [NC]
RewriteCond %{REQUEST_URI} !index\.htm            [NC]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule  .  local/applications/bin/oldsite/index.htm [R=301,L]

第一组规则适用于本地主机并永久重定向:

http://localhost/mysite/filename.htm

至:

http://localhost/mysite/local/applications/bin/oldsite/filename.htm

filename.htm传入 URL 中不存在时,filename.htm替换 URL 中始终为index.htm

该字符串mysite被假定为固定字符串,而filename被假定为变量。


第二个规则集用于 Web 服务器,仅永久重定向

http://mysite.com/

至:

http://mysite.com/local/applications/bin/oldsite/index.htm

在最后一种情况下,如果传入 URL 包含任何其他路径,则不应用该规则。

对于静默映射,请R=301[R=301,L].

将上述规则集复制到本地和远程根目录中的 .htaccess 文件中。

于 2013-02-10T02:56:16.257 回答
0

这可能会让您开始(未经测试):检查请求是否指向特定子文件夹的条件。如果是这样,请将请求重定向到子文件夹。如果需要,您可以在目标中使用。如果更合适,您可以使用另一种来代替 HTTP 状态 301。

RewriteCond %{REQUEST_URI} !^/(local/applications/bin/oldsite/.*)$
RewriteRule ^(.*)$ http....n/subfolder/%1 [R=301,L]
于 2013-02-09T22:12:32.830 回答
-1

似乎您想将“oldsite”目录设为您的文档根目录- 对吧?

于 2013-02-09T21:51:53.727 回答