![](/img/trans.png)
[英]Htaccess 301 redirect from one directory to its subdirectory and keeping the main directory url accesible
[英].htaccess 301 redirect from one subdirectory to another and preserve folder/directory structure
我已經做了很多有關如何執行此操作的搜索,但是,在保留原始文件夾/目錄結構的同時,一個解決方案似乎都無法解決從一個子目錄重定向到另一個子目錄這一特定問題。
例如,我想將所有傳入的深層鏈接從:example.com/post/123重定向到example.com/archive/post/123
基本上,我只想將原始的Wordpress博客從根目錄移到子目錄,但是我有一些受歡迎的傳入鏈接,並且我希望它們不會中斷。
如果您有任何幫助,或者有任何類似的移動博客經驗但仍保留其傳入鏈接的人,將不勝感激。
謝謝,
喬希
請嘗試以下方法:
對於每個鏈接,請在.htaccess
文件中編寫以下內容
redirect 301 /OldSubdirectoy/old/old.htm http://www.domainname.com/NewSubdirectory/new/new/new.htm
使用此結構為您的每個受歡迎的鏈接撰寫內容,以保持SEO。
不久前,我正確地找到了答案,並在Medium上寫了一篇關於它的文章 :
基本上,這是我在根目錄下的.htaccess
中所需的代碼:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(p/.*)$ http://phocks.org/historic/$1 [R=301,L]
RewriteRule ^(contact.*)$ http://phocks.org/historic/$1 [R=301,L]
RewriteRule ^(about.*)$ http://phocks.org/historic/$1 [R=301,L]
RewriteRule ^(wp-content.*)$ http://phocks.org/historic/$1 [R=301,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.