如何通过编辑htaccess文件将URL重定向到新URL

问题描述 投票:0回答:2

例如 旧网址:https://www.example.com/first/second/third/FILE_NAME 新网址:https://www.newdomain/new_path/FILE_NAME

所以我想要的是,只要在页面中找到旧URL,只需将其替换为除了FILE_NAME之外的新URL

试过:

RewriteCond %{REQUEST_URI} ^/templates/test1/default/update/mach4/cache/default/$
RewriteRule ^(.*)$ https://cdn.example.com/new-folder/ [R=301,L]

实例: 我的旧网址是https://www.tracker.com/templates/applications/default/themes/default/logo.png

新网址应该是https://cdn.tracker-files.com/tracker-cdn/logo.png

除了文件名整个网址需要更改(就像字符串替换功能)

.htaccess mod-rewrite
2个回答
0
投票

medium中尝试这个tuto,或者给我们你的htaccess文件代码


0
投票

你可以使用RedirectMatch

要将example.com/first/second/third/file重定向到newdomain.com/first/second/third/file,您可以在example.com/.htaccess中使用以下重定向。

RedirectMatch 301 ^/first/second/third/file$ http://newdomain.com/new_path/file

如果您有多个相同格式的URL,则可以使用正则表达式而不是URI。

RedirectMatch 301 ^/[^/]+/[^/]+/[^/]+/(.+) $ http://newdomain.com/new_folder/$1

以上将把example.com/folder1/folder2/folder3/thisfile重定向到newdomain.com/new_folder/thisfile

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.