使用htaccess从URL中删除en

时间:2018-06-12 10:13:13

标签: .htaccess

我有这个页面结构,用于多语言网站:

- Home En (/en)
   - Page1 En (/en/page1)
   - Page2 En (/en/page2)

- Home Es (/es)
   - Page1 Es (/es/page1)
   - Page2 Es (/es/page2)   

默认语言为en,我想使用en规则隐藏网址中的htaccess

这是我htaccess文件中的当前内容:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/perch
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /perch/core/runway/start.php [L]

我已尝试将此RewriteRule ^/en/(.+)$ /$1 [QSA]添加到第二行,但它没有任何影响。

RewriteEngine On
RewriteRule ^/en/(.+)$ /$1 [QSA] 
RewriteCond %{REQUEST_URI} !^/perch
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /perch/core/runway/start.php [L]

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

在您的网站root .htaccess:

中这样做
RewriteEngine On

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/en/(\S+) [NC]
RewriteRule ^ /%1? [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!en/). en%{REQUEST_URI} [L,NC] 

RewriteCond %{REQUEST_URI} !^/perch [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /perch/core/runway/start.php [L]