htaccess 301重定向,主站点移动到一个文件夹

时间:2011-11-23 01:29:55

标签: .htaccess

我正在努力去抓住htaccess,但我很难搞清楚这一点。

假设我有http://www.example.com

我打算将整个网站移动到像http://www.example.com/folder/

这样的文件夹中

我创建了一个文件夹并将其中的所有内容移动了我如何确保如果有人通过谷歌找到我,他们将被重定向到正确的页面。

例如,http://www.example.com/view.php?id=5变为http://www.example.com/folder/view.php?id=5

感谢你给我的任何帮助。

2 个答案:

答案 0 :(得分:1)

如果您想将每个请求从 example.com 重定向到 example.com/folder ,包括css,js,html,php等文件,请使用以下内容

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !^/folder.*$ [NC]
RewriteRule ^(.*)$ /folder/$1 [L,R=301]

答案 1 :(得分:0)

如果您使用的是apache,请尝试:

RewriteEngine on
# make sure the requested URI doesn't go to an existing  file/directory (e.g. starts with /folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# make sure the requested URI goes to an existing file/directory inside /folder
RewriteCond %{DOCUMENT_ROOT}/folder%{REQUEST_URI} -f  [OR]
RewriteCond %{DOCUMENT_ROOT}/folder%{REQUEST_URI} -d
RewriteRule ^(.*)$ /folder/$1 [L,R=301]