[英].htaccess Url Redirect Issues
我在域中有两个已重命名的文件夹。 我想将一些重定向脚本添加到我的.htaccess文件中,以便具有旧链接的用户可以到达正确的位置。 我尝试使用using;
RedirectMatch 301 /oldfolder/subsection-01/(.*) example.com/new-folder/subsection/$1
RedirectMatch 301 /oldfolder/(.*) example.com/new-folder/$1
他们都工作了! 但是我所有的图像链接都断开了,因为它们在服务器上的文件路径具有以下路径:
example.com/sites/default/files/**oldfolder**/filename.jpg
我一直在寻找一种方法,要么排除对.jpg文件的引用,要么确保仅对包含域uri的文件夹起作用,例如“ example.com/oldfolder”,但无济于事。
我尝试了以下技术;
RedirectMatch 301 %{HTTP_HOST} example\.com/oldfolder/subsection-01/(.*) example.com/new-folder/subsection/$1
RedirectMatch 301 example.com/oldfolder/(.*) example.com/new-folder/$1
RewriteRule %{HTTP_HOST}.example\.com/oldfolder/subsection-01/$ example.com/new-folder/subsection/$1 [L]
RewriteRule %{HTTP_HOST} ^www\.example\.com/oldfolder/(.*) example.com/new-folder/$1 [R=301,L]
但是它们要么导致服务器501错误,要么什么都不做。
我希望社区提供任何有用的帮助。
谢谢。
在正则表达式中使用开始锚,以确保仅在开始时才匹配您的模式:
RedirectMatch 301 ^/oldfolder/subsection-01/(.*) http://example.com/new-folder/subsection/$1
RedirectMatch 301 ^/oldfolder/(.*) http://example.com/new-folder/$1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.