2015-12-14 77 views
0

我想弄清楚如何在我的htaccess文件中設置一些重定向。動態htaccess重寫

我們動態網址加載我們的商店,例如:

/位置/新約克

新約克是動態部分

我們有容納諸如

不同的路徑舊網址

/位置/新約克/本地商店

我希望能夠把所有地點/動態城市,並將其轉發到新URL

所以

/位置/新約克/本地存儲/提供

應該轉到/位置/新約克/電流提供

+0

它總是/ locations/{location}/local-store/offers還是有其他的url? – slapyo

+0

還有其他的,但都遵循類似的方法 – West55

+0

他們是什麼?您可能能夠在1個RewriteRule中全部覆蓋它們,而不是單獨使用它們。只取決於他們是什麼。 – slapyo

回答

1
RewriteRule ^locations/(.*)/local-store/offers locations/$1/current-offers [L,R=301,QSA] 
RewriteRule ^locations/(.*)/local-store/hot-tubs locations/$1/hot-tubs [L,R=301,QSA] 
RewriteRule ^locations/(.*)/local-store/pre-owned locations/$1/pre-owned [L,R=301,QSA] 
RewriteRule ^locations/(.*)/local-store/client-reviews locations/$1/reviews [L,R=301,QSA] 

好了,所以我米沒有看到一種方法來輕鬆使用1重寫小冊子覆蓋所有4個案例。但是你可以看到確保所請求的URL遵循這樣的模式。

^locations/{location}/local-store/offers 

然後您將該位置放入您要寫入的新網址中。

L  # means it's the last rule, don't try to match anymore 
R=301 # means redirect the old url to the new one 
QSA # means append any query string parameters to the new url 
+0

完美的工作完美無瑕。非常感謝! – West55