Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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 将多个URL(URL中包含的编号)重定向到同一个新URL_.htaccess_Redirect_Mod Rewrite - Fatal编程技术网

.htaccess 将多个URL(URL中包含的编号)重定向到同一个新URL

.htaccess 将多个URL(URL中包含的编号)重定向到同一个新URL,.htaccess,redirect,mod-rewrite,.htaccess,Redirect,Mod Rewrite,我有3个URL,如: http://example.com/archives/2001_2005/ http://example.com/archives/2006/ http://example.com/archives/2007/ 如何使用.htaccess到301将它们全部重定向到: http://example.com/archives/2001-2007/ 我在下面尝试了这一点,但不起作用(我更喜欢尽可能简单的一行): 您可以使用重定向匹配: RedirectMatch 301 ^

我有3个URL,如:

http://example.com/archives/2001_2005/
http://example.com/archives/2006/
http://example.com/archives/2007/
如何使用.htaccess到301将它们全部重定向到:

http://example.com/archives/2001-2007/
我在下面尝试了这一点,但不起作用(我更喜欢尽可能简单的一行):


您可以使用重定向匹配:

RedirectMatch 301 ^/archives/(2001_2005|2006|2007) http://example.com/archives/2001-2007

测试此功能之前,请清除浏览器缓存。

重写引擎是否已打开?它是否位于VirtualHost或Directory部分?是的,服务器的所有设置都正确。在我的示例/解决方案中,状态为410(已消失),并且没有发生重定向。当执行单独的重定向时,例如:redirect 301/archives/2006/它可以正常工作。但是我想要一个更简单的规则,它涵盖了一行中的所有内容。那么使用ErrorDocument 410/archives/2001-2007如何,它将已删除内容的请求路由到新的URL?如果可能的话,我希望更简单的解决方案是重定向,而不是使用重写。
RedirectMatch 301 ^/archives/(2001_2005|2006|2007) http://example.com/archives/2001-2007