2013-05-28 108 views
1

我有重複URL的大名單,我需要做一些重定向重定向複製htaccess的網址

www.mysite.com/mypage/name2_68.html 
www.mysite.com/jjj/name2_68.html 
www.mysite.com/aa/name2_68.html 
www.mysite.com/5654/name2_68.html 

www.mysite.com/mypage/myname87.html 
www.mysite.com/6584/myname87.html 
www.mysite.com/any-number/myname87.html 
www.mysite.com/any_word/myname87.html 

所有我需要做的就是把它們重定向到

www.mysite.com/mypage/myname87.html 
www.mysite.com/mypage/name2_68.html 

所以所有的網址與

www.mysite.com/anycharactere/example1.html  

將被重定向到

www.mysite.com/mypage/example1.html 
+0

您當前的重寫說明以何種方式未能滿足您的要求?你會發表這些聲明嗎? –

+0

嗨,我不知道iam仍然是小菜抱歉 – BerrKamal

+0

您需要閱讀mod_rewrite文檔以獲得對該過程的基本瞭解。隨時在這裏問你寫了一些代碼。 –

回答

1

這應該工作。

RewriteEngine on 
RewriteBase/

RewriteCond %{REQUEST_URI} !^/mypage/? 
RewriteRule ^[^/]+/(.*\.html?)$ /mypage/$1 [R=301,L] 
+0

ty爲您的答案我認爲這是工作,但有一個大問題,當我添加此規則到我的htaccess所有我的網站圖像和文本更改somthing與此代碼不好 – BerrKamal

+0

更改爲?你能查看源代碼並讓我知道你的發現嗎? .htaccess本身不能篡改你的文件。它可以簡單地路由到不同的URL。就這樣。 –

+0

啊,我明白了。我沒有將規則限制在只有htm/html文件。它應該現在工作正常。請檢查更新。爲麻煩抱歉。 –

0

把它放在你的.htaccess

RewriteEngine On 
RewriteRule .*/([^/]+.html)$ /mypage/$1 
+0

ty爲答案,但它沒有工作我試過,但該網址並沒有重定向 – BerrKamal

+0

@BerrKamal測試http://htaccess.madewithlove.be/和http://martinmelin.se/rewrite-rule-tester/。嘗試在'RewriteRule'前添加'RewriteBase /' – wachme

+1

由於'。*'會導致無限重定向。在線模擬器只顯示你一次通過你的規則。請看看我的答案以供參考。 –