Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
Php 切换模式重写的URL_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php 切换模式重写的URL

Php 切换模式重写的URL,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我们在PHP站点中使用mod重写URL,这是我们使用的重写规则: RewriteRule ^category/([^.]+)/([0-9]+)/([^.]+)/([0-9]+) categories.php?c_id=$2&filters=$3&_p=$4&area=category&areaname=$1 但是,另一个系统的用户正在切换到我们的设置,并希望将其所有旧页面转换为新的对等页面。例如,这个URL: http://domain.com/categori

我们在PHP站点中使用mod重写URL,这是我们使用的重写规则:

RewriteRule ^category/([^.]+)/([0-9]+)/([^.]+)/([0-9]+) categories.php?c_id=$2&filters=$3&_p=$4&area=category&areaname=$1
但是,另一个系统的用户正在切换到我们的设置,并希望将其所有旧页面转换为新的对等页面。例如,这个URL:

http://domain.com/categories/clothing/5/1
变成:

http://domain.com/category/clothing/5/0-0-0-0/1
是否可以在一个重写规则或重写匹配(或类似)中实现这一点,我最初的想法是这样的:

RewriteRule /categories/(.*)/(.*)/1 /category/$1/$2/0-0-0-0-0-0-0-0/1 [R=301,L]
没有,有什么想法吗

还使用RedirectMatch尝试了此操作,但也不起作用:

RedirectMatch /categories/(.*)/(.*)/1 http://domain.com/category/$1/$2/0-0-0-0-0-0-0-0/1

你的例子是从我看到的相反方向重定向到你想要的方向


/category/abc/def/0-0-0-0-0-0/1
/categories/abc/def/1
我用这个规则修正了自己:

RedirectMatch 301 /categories/(.*)/(.*)/(.*) http://domain.com/category/$1/$2/0-0-0-0-0-0-0-0/$3

下面是一个mod_重写示例:

RewriteRule ^categories/([^/]+/[^/]+)/([^/]+)$ /category/$1/0-0-0-0/$2 [L,R=301]

只是注意到我把它们贴错了方向,仍然不起作用,尽管是故意在
RewriteRule/categories…
中使用了斜杠?