Php .htaccess重定向忽略了URL的几个部分
我正试图改变方向Php .htaccess重定向忽略了URL的几个部分,php,linux,apache,.htaccess,redirect,Php,Linux,Apache,.htaccess,Redirect,我正试图改变方向 http://www.example.com/shop/childrens-shinnerz-by-size/extra-small 到 这样 Redirect 301 /shop/childrens-shinnerz-by-size/extra-small /sports-goods/childrens-shinnerz/all-extra-small-5-7-yrs 但它在错误的url上重定向 http://www.example.com/sports-goods/ch
http://www.example.com/shop/childrens-shinnerz-by-size/extra-small
到
这样
Redirect 301 /shop/childrens-shinnerz-by-size/extra-small /sports-goods/childrens-shinnerz/all-extra-small-5-7-yrs
但它在错误的url上重定向
http://www.example.com/sports-goods/childrens-shinnerz/extra-small
因此,零件全部-
和-5-7-yrs
被忽略
如何重定向到正确的URL?使用此选项,应该可以:
RedirectMatch 301 http://www.example.com/shop/childrens-shinnerz-by-size/extra-small(.*) http://www.example.com/sports-goods/childrens-shinnerz/all-extra-small-5-7-yrs/$1
来源:如果您正在使用站点根目录中的.htaccess文件
RewriteRule ^shop/childrens-shinnerz-by-size/extra-small(.*)$ http://www.example.com/sports-goods/childrens-shinnerz/all-extra-small-5-7-yrs/$1 [R=301,NC,L]
我想办法
RedirectMatch 301 ^/shop/childrens-shinnerz-by-size/extra-small$ /sports-goods/childrens-shinnerz/all-extra-small-5-7-yrs
这是我想要的工作方式我已经在我的服务器上测试过了,效果很好
也许你的apache有问题,试着测试其他类似的东西
Redirect 301 /retiredpage.html http://www.example.com/newpage.html
如果你没有得到想要的结果,那就玩一玩吧,这意味着你可能需要更新你的apache试着用引号包装/sports goods/childrens shinnerz/all-extra-small-5-7-yrs?不-我用引号得到了同样的结果。我提到,当url中的数字和关键字
all
时,它不起作用!如果在此之前.htaccess文件中有任何规则,请尝试“全部注释”并对其进行测试,可能在它以这种方式运行之前有一条规则
Redirect 301 /retiredpage.html http://www.example.com/newpage.html