[英]Redirect from subfolder and folder to main folder with htaccss
我想要重定向鏈接:
http://www.domain.com/folder/file.php **to* http://www.domain.com/file.php
http://www.domain.com/folder/folder/file.php **to* http://www.domain.com/file.php
到目前為止,我已經嘗試過了
Redirect 301 /folder/file.php http://www.domain.com/file.php
Redirect 301 /folder/folder/file.php http://www.domain.com/file.php
這正在工作。我有100個以上這樣的文件進行重定向,是否有一種簡單的方法來減少我的代碼,以便我可以使用更少的代碼來進行更多重定向。 謝謝你的幫助!
您可以使用RedirectMatch指令:
將以下重定向放在其他規則之上,放在您的root / .htaccess文件中:
RedirectMatch 301 ^/folder/folder/([^/]+)/?$ /$1
RedirectMatch 301 ^/folder/([^/]+)/?$ /$1
您只需在根.htaccess中使用一條規則即可進行所有這些重定向:
RedirectMatch 301 /[^/]+/([^/]+)/?$ /$1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.