[英]Redirect folder to another with htaccess
我遇到了將文件夾重定向到新文件夾的問題。 我不想使用php header()或類似的東西,我想用mod_rewrite模塊和.htaccess文件來實現這個效果。
我要做的是將http://domain.com/test/地址重定向到http://domain.com/new/ 。 它不是重寫,它只需將用戶從舊地址移動到新地址。 我試圖使用:
RewriteRule ^test/(.*) new/$1
但它拋出404錯誤導致目錄測試不存在。 如何在不創建其他文件夾的情況下重定向用戶?
您可以使用外部重定向:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^test/(.*)$ /new/$1 [L,NC,R=302]
如果您不想要外部重定向(瀏覽器中沒有更改URL),請刪除R
標志:
RewriteRule ^test/(.*)$ /new/$1 [L,NC]
PS:請詳細說明: It's not rewriting, it has to just move the user from old to new address
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.