Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 301重定向到新目录,不带.html_.htaccess_Redirect_Mod Rewrite - Fatal编程技术网

.htaccess 301重定向到新目录,不带.html

.htaccess 301重定向到新目录,不带.html,.htaccess,redirect,mod-rewrite,.htaccess,Redirect,Mod Rewrite,我想301重定向一个新目录中的数百个URL,并且不以.html结尾 旧URL:domain.com/content/lorem ipsum.html 新URL:domain.com/new/lorem ipsum 因此,我需要一个重定向,将所有URL从/content/重定向到/new/,并将所有URL从.html重定向到不带.html。或者可以在一个重定向中完成,比如 旧版:domain.com/content/*.html 新建:domain.com/new/*您可以使用以下重定向: Red

我想301重定向一个新目录中的数百个URL,并且不以.html结尾

旧URL:
domain.com/content/lorem ipsum.html

新URL:
domain.com/new/lorem ipsum

因此,我需要一个重定向,将所有URL从
/content/
重定向到
/new/
,并将所有URL从
.html
重定向到不带
.html
。或者可以在一个重定向中完成,比如

旧版:
domain.com/content/*.html


新建:
domain.com/new/*
您可以使用以下重定向:

RedirectMatch 301 ^/dir/(.+)\.html$ http://example.com/new/$1

您可以使用以下重定向:

RedirectMatch 301 ^/dir/(.+)\.html$ http://example.com/new/$1

您应该查看并阅读一些有关如何使用它的教程:

要帮助您开始并解决当前问题,请尝试以下方法:

RewriteEnging On
RewriteRule ^content/(.+)\.html /new/$1 [R=301,L]
此处演示:

说明:在模式中,我们告诉服务器查找以内容开头的URL-
^content/
,后跟一个或多个字符-
(.+)
,以.html-
\.html
结尾

注意
+
周围的
()
——这指示Apache将匹配保存到变量中-
$1
。因此,在您的示例中,
lorem ipsum
存储在
$1

然后可以在替换中访问
$1
,我们告诉它转到
/new/
,然后是
$1
中存储的内容


最后,在标志部分,我们指示Apache发出301重定向-
R=301
并停止处理进一步的规则
L
,因为我们不需要它来处理这个现在被重定向的请求。

您应该看看并阅读一些关于如何使用它的教程:

要帮助您开始并解决当前问题,请尝试以下方法:

RewriteEnging On
RewriteRule ^content/(.+)\.html /new/$1 [R=301,L]
此处演示:

说明:在模式中,我们告诉服务器查找以内容开头的URL-
^content/
,后跟一个或多个字符-
(.+)
,以.html-
\.html
结尾

注意
+
周围的
()
——这指示Apache将匹配保存到变量中-
$1
。因此,在您的示例中,
lorem ipsum
存储在
$1

然后可以在替换中访问
$1
,我们告诉它转到
/new/
,然后是
$1
中存储的内容


最后,在标志部分,我们指示Apache发出301重定向-
R=301
,并停止处理进一步的规则
L
,因为我们不需要它来处理现在被重定向的请求。

到目前为止,您尝试了什么?请给我们看一些代码。没什么,我不知道怎么做。。。我有重定向方面的基本经验,但这是一个很高的水平。:-)到目前为止你试过什么?请给我们看一些代码。没什么,我不知道怎么做。。。我有重定向方面的基本经验,但这是一个很高的水平。:-)