2013-10-28 81 views
1

我想重寫一個URL,我不希望現有鏈接再轉到舊頁面(地址)。重定向並重寫URL htaccess

Options +FollowSymlinks 
RewriteEngine on 
RewriteRule ^about-us$ /shop/static_page\.php\?static_page_id=3 [NC,L] 

這是我的.htaccess文件看起來像此刻,它工作正常 - 儘管當我在一個正常的重定向規則添加如:

Redirect 301 /shop/static_page.php?static_page_id=3 http://example.com/about-us 

這不起作用 - 就好像這條線不存在一樣。請有任何想法嗎?

回答

1

兩件事:

  1. 規則的排序非常重要,所以有301的內部重寫之前
  2. 不要mod_rewrite

下面的代碼應該爲你工作混mod_alias規則:

Options +FollowSymlinks 
RewriteEngine on 

# external redirect from actual URL to pretty one 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+shop/static_page\.php\?static_page_id=3[\s&] [NC] 
RewriteRule^/about-us? [R=301,L] 

# internal forward from pretty URL to actual one 
RewriteRule ^about-us/?$ /shop/static_page\.php?static_page_id=3 [NC,L,QSA] 
+0

感謝您的提示,您是否能夠發佈一個例子它應該是什麼樣子?非常感謝:) – Tim

+0

@Tim:剛剛使用示例代碼進行編輯。 – anubhava

+0

美麗。謝謝*非常* @anubhava – Tim