Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
URL 301通过php中的.htaccess文件重定向_Php_Apache_.htaccess_Redirect - Fatal编程技术网

URL 301通过php中的.htaccess文件重定向

URL 301通过php中的.htaccess文件重定向,php,apache,.htaccess,redirect,Php,Apache,.htaccess,Redirect,上面的重定向规则将我重定向到下面的URL www.example.com/products/223/category/sub_category/product_name.html RewriteRule ^products/([^/]+)/([^.]+)\.html$ /$2/p$1 [L,NC,R=301] 我想更新它,以便它将重定向 从 到 我想用前缀“p”显示产品名称(“\u”应替换“-”)和产品ID。请尝试以下操作: www.example.com/product-name/p223

上面的重定向规则将我重定向到下面的URL

www.example.com/products/223/category/sub_category/product_name.html

RewriteRule ^products/([^/]+)/([^.]+)\.html$ /$2/p$1 [L,NC,R=301]
我想更新它,以便它将重定向 从

我想用前缀“p”显示产品名称(“\u”应替换“-”)和产品ID。请尝试以下操作:

www.example.com/product-name/p223
这将重定向:

RewriteEngine On
RewriteRule ^/?product/([^/]+)/([^/]+)/([^/]+)/([^_]+)_([^.]+)\.html$ http://example.com/$4-$5/p$1 [NC,R=301,L]


下面的重定向适用于我

 www.example.com/product-name/p223

谢谢你的回复,我忘记提到了,但是url中的类别和子类别也是动态的。谢谢你的回复。重写规则^products/(\d+)/(.*)/(.*)/([^.]+)([^.]+).html$/$4-$5/p$1[L,NC,R=301]这对我很有效。
RewriteEngine On
RewriteRule ^/?product/([^/]+)/([^/]+)/([^/]+)/([^_]+)_([^.]+)\.html$ http://example.com/$4-$5/p$1 [NC,R=301,L]
 www.example.com/products/223/category/sub_category/product_name.html
 www.example.com/product-name/p223
RewriteRule ^products/(\d+)/(.*)/(.*)/([^_]+)_([^.]+).html$ /$4-$5/p$1 [L,NC,R=301]