簡體   English   中英

如何重定向除htaccess中某些文件夾之外的所有流量?

[英]How to redirect all traffic apart from certain folders in htaccess?

我一直在拉我的頭發。 我想將所有流量重定向到我的新站點。

出於爭論的緣故,新站點是mysite.org。 但是,有些頁面,規則和文件夾要重定向到新站點上-如果用戶不訪問這些文件夾或規則-應該將其重定向到我的站點嗎?

redirect 301 / http://example.org
redirect 301 /index.php http://example.org
redirect 301 /index.html http://example.org
redirect 301 /contact.php http://example.org/contact-us
redirect 301 /store-locator/list.php http://example.org/store-locator
redirect 301 /store-locator/ http://example.org/store-locator
redirect 301 /about.php http://example.org/about-us
redirect 301 /customer-care.php http://example.org/contact-us
redirect 301 /hq-location.php http://example.org/store-locator
redirect 301 /privacy.php http://example.org/privacy
redirect 301 /terms.php http://example.org/terms
redirect 301 /policy.php http://example.org/returns

使用RedirectMatch而不是Redirect會更好,因為RedirectMatch使用正則表達式並且僅匹配匹配的URI,而Redirect匹配以提供的模式開頭的任何URI,因此您的第一個規則將始終執行,從而使所有后續規則均無效

RedirectMatch 301 ^/$ http://example.org
RedirectMatch 301 ^/index\.(html|php)$ http://example.org
RedirectMatch 301 ^/contact\.php$ http://example.org/contact-us
RedirectMatch 301 ^/store-locator/list\.php$ http://example.org/store-locator
RedirectMatch 301 ^/store-locator/?$ http://example.org/store-locator
RedirectMatch 301 ^/about\.php$ http://example.org/about-us
RedirectMatch 301 ^/customer-care\.php$ http://example.org/contact-us
RedirectMatch 301 ^/hq-location\.php$ http://example.org/store-locator
RedirectMatch 301 ^/privacy\.php$ http://example.org/privacy
RedirectMatch 301 ^/terms\.php$ http://example.org/terms
RedirectMatch 301 ^/policy\.php$ http://example.org/returns

清除瀏覽器緩存后,請確保對其進行測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM