htaccess重写到特定网址不起作用

时间:2016-05-02 11:33:11

标签: .htaccess mod-rewrite

我尝试将所有语言重写到网站上的/ en /。但我做错了什么,不知道是什么。 所有域请求(例如https://www.shop.com/de/https://www.shop.com/)都必须重写为https://www.shop.com/en/

为什么我需要这个?首先,我的商店必须准备好/ en / language。当一切正常时,我会添加/ de /然后/ nl /.

有人为我提供解决方案吗?会很好。

这里是我在htaccess中使用的代码:

<IfModule mod_rewrite.c>
RewriteEngine     On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule . /index.php [L]
RewriteRule https://www.shop.com/de/ https://www.shop.com/en/
RewriteRule https://www.shop.com/nl/ https://www.shop.com/en/
RewriteRule https://www.shop.com https://www.shop.com/en/
RewriteRule https://www.shop.com/ https://www.shop.com/en/
</IfModule>

1 个答案:

答案 0 :(得分:0)

您无法匹配RewriteRule中的完整网址。

您可以使用以下规则:

RewriteEngine On
RewriteBase /

RewriteRule ^(de|nl)?/?$ /en/ [L,NC,R=301]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule . index.php [L]