簡體   English   中英

.htaccess不會從舊網址重定向到新網址3

[英].htaccess is not redirecting from old url to new url 3

我是.htaccess新手。 我已經閱讀了文檔,但是無法使重定向規則起作用。

我想要以下的RewriteRule

http://mywebsite.com/restaurants/59393/the-grounds-of-alexandria.htm

http://mywebsite.com/restaurants/the-grounds-of-alexandria

我已經嘗試過了

RewriteRule ^(.*)/[0-9]/(.*)$ ^(.*)/(.*)/$ [R=301,L]

您還如何獲取子域並將其放在所有鏈接的前面,像這樣

http://sydney.mywebsite.com/restaurants/59393/the-grounds-of-alexandria.htm

http://mywebsite.com/sydney/restaurants/the-grounds-of-alexandria

但沒有結果。

重寫很簡單:

http://mywebsite.com/restaurants/59393/the-grounds-of-alexandria.htm
to
http://mywebsite.com/restaurants/the-grounds-of-alexandria

您的重寫規則RewriteRule ^(.*)/[0-9]/(.*)$ ^(.*)/(.*)/$ [R=301,L]對於網址而言過於全局。 其次,您只說[0-9]意味着只有一位數字。

RewriteRule ^([^/]+)/[0-9]+/([^.]+)\.htm$ /$1/$2 [R=301,L]

試試這個;)


編輯(針對第二個問題):

http://sydney.mywebsite.com/restaurants/59393/the-grounds-of-alexandria.htm
to 
http://mywebsite.com/sydney/restaurants/the-grounds-of-alexandria

當然;)您必須在其中使用RewriteCond。

RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^([^\.]+)\.mywebsite\.com/([^/]+)/[0-9]+/([^.]+)\.htm
RewriteRule ^.*$ http://mywebsite.com/%1/%2/%3 [R=301,L]

為了便於說明,可以從RematchRule語句中使用的上一個匹配項中使用%1-3。 這應該適用於每個子域,並且僅適用於子域。 如果需要特定的子域,則可以將第一行調整為^(sidney|othersubdomain|anothersubdomain)\\.mywebsite\\.com...

暫無
暫無

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

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