.htaccess htaccess 301重定向,主站点移动到文件夹中

.htaccess htaccess 301重定向,主站点移动到文件夹中,.htaccess,.htaccess,我真的很难理解htaccess,但我很难弄明白这一点 假设我有 我计划将整个网站移动到这样一个文件夹中 我创建了一个文件夹并移动了其中的所有内容。我如何确保如果有人通过谷歌找到我,他们将被重定向到正确的页面 例如,成为 感谢您提供的任何帮助。如果您正在使用apache,请尝试: RewriteEngine on # make sure the requested URI doesn't go to an existing file/directory (e.g. starts with /fo

我真的很难理解htaccess,但我很难弄明白这一点

假设我有

我计划将整个网站移动到这样一个文件夹中

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

例如,成为


感谢您提供的任何帮助。

如果您正在使用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]

如果您正在使用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]

如果要将每个请求从example.com重定向到example.com/folder,包括css、js、html、php等文件,请使用以下命令

RewriteEngine On
RewriteBase /

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

如果要将每个请求从example.com重定向到example.com/folder,包括css、js、html、php等文件,请使用以下命令

RewriteEngine On
RewriteBase /

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

谢谢,但这对我不起作用。它会将其重定向到,依此类推/folder/exist?否则您可以添加
RewriteCond%{REQUEST\u URI}^/文件夹/
就在“重写引擎”(RewriteEngine)的下方,但它对我不起作用。它会将其重定向到,依此类推/folder/exist?否则您可以添加
RewriteCond%{REQUEST\u URI}^/文件夹/
就在书架的右下方。它似乎起作用了。无论如何,我是否可以将指向example.com/view.php?id=1的流量重定向到example.com/folder/view.php?id=1,这样如果客户转到第一个url,它仍然显示一个页面,而不是404?Bastien,
example.com/view.php?id=1
应该按照上述规则重定向到
example.com/folder/view.php?id=1
。如果它这样做并返回404,您可以验证文件夹directoryThank中是否存在view.php吗。它似乎起作用了。无论如何,我是否可以将指向example.com/view.php?id=1的流量重定向到example.com/folder/view.php?id=1,这样如果客户转到第一个url,它仍然显示一个页面,而不是404?Bastien,
example.com/view.php?id=1
应该按照上述规则重定向到
example.com/folder/view.php?id=1
。如果它这样做并返回404,您能验证view.php是否存在于文件夹目录中吗