问题HTACCESS:如何赋予优先级绝对路径?

时间:2019-03-22 10:26:48

标签: .htaccess

我们正忙于为我们的网上商店更改名称,我正在HTACCESS上进行重定向1700个链接的工作。在这1700个链接中,有177个链接在我们的新网上商店中正在更改。因此,它们必须处于HTACCESS中。其他链接保持不变,我现在使用一般重写器将其重定向。

现在唯一的问题是他对确切的链接不满意。例如,请参见下面的我的HTACCESS。

RewriteEngine on

# Redirect to domain with www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/(.*)$ https://www.new.nl/vloerkleden/ [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/vintage-vloerkleed/(.*)$ https://www.new.nl/vloerkleden/vintage-vloerkleed/ [R=301,L]

RewriteCond %{HTTP_HOST} ^old.nl [NC,OR]
RewriteCond %{HTTP_HOST} ^www.old.nl [NC]
RewriteRule ^(.*)$ https://www.new.nl/$1 [L,R=301,NC]

当我现在在浏览器中输入以下URL www.old.nl/vloerkleden/catagorie/vintage-vloerkleed/时,他将我链接到www.new.nl/vloerkleden,而不是www.new.nl/vloerkleden/vintage -vloerkleed。

1 个答案:

答案 0 :(得分:0)

您在此行中遇到的问题:

RewriteRule ^vloerkleden/categorie/(.*)$ https://www.new.nl/vloerkleden/ [R=301,L]

Nothig不会用(.*)$来代替https://www.new.nl/vloerkleden/,因此,它应该看起来像这样https://www.new.nl/vloerkleden/$1,因为$1将以模式表示(.*)

此外,您可以使用其他规则来执行此操作,也可以像这样汇总您的规则:

RewriteEngine on

# the folwoing rules will force every request for both old & new into https://wwww:

RewriteCond %{HTTPS} off  [OR]
RewriteCond %{HTTP_HOST} ^(?!.*www\.)(.*)$
RewriteRule .* https://www.%1%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/(.*)$ https://www.new.nl/vloerkleden/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/vintage-vloerkleed/(.*)$ https://www.new.nl/vloerkleden/vintage-vloerkleed/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?old.nl [NC]
RewriteRule ^(.*)$ https://www.new.nl/$1 [L,R=301,NC]

注意:清除浏览器缓存,然后进行测试。