简体   繁体   English

.htaccess - 当结尾没有斜线时的子域重定向(我想要subdomain.domain.eu/en - > subdomain.domain.eu/en/)

[英].htaccess - subdomain redirection when there's no slash at the end (I want subdomain.domain.eu/en -> subdomain.domain.eu/en/)

I have this code in my .htaccess file: 我在.htaccess文件中有这个代码:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

RewriteCond %{HTTP_HOST} ^www\.subdomain\.domain\.eu [NC]
RewriteRule ^(.*)$ https://subdomain.domain.eu/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.eu$ [NC]
RewriteRule ^((?!subdomain/).*)$ /subdomain/$1 [L,NC]

This thing shows to users content of folder subdomain when they navigate to subdomain.domain.eu . 这个东西在用户导航到subdomain.domain.eu时向用户显示文件subdomain内容。 It works OK. 它运作正常。

Recently I added support of different languages to my website. 最近我在我的网站上添加了不同语言的支持。 When English speaking people enter subdomain.domain.eu they are redirected to subdomain.domain.eu/en/ . 当说英语的人进入subdomain.domain.eu他们会被重定向到subdomain.domain.eu/en/ And it works OK. 它运作正常。

However, here comes the problem - when somebody navigate to subdomain.domain.eu/en (without the slash at the end) they're redirected to subdomain.domain.eu/en/subdomain/ and I want them to be redirected to subdomain.domain.eu/en/ . 然而,问题出现了 - 当有人导航到subdomain.domain.eu/en (最后没有斜线)时,他们被重定向到subdomain.domain.eu/en/subdomain/并且我希望它们被重定向到subdomain.domain.eu/en/ How to achieve that? 怎么实现呢?

I'm not sure if I didn't mess up something else but adding this (as arkascha suggested) helped: 我不确定我是不是搞砸了别的东西,但添加这个(如arkascha建议)帮助:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$        /$1$2/ [L,R=301]

@edit @编辑

Yeah, it didn't work as expected, but this is: 是的,它没有按预期工作,但这是:

RewriteCond %{REQUEST_URI} !\.[a-z0-9]+$ [NC]
RewriteRule ^(.*)([^/])$ https://%{HTTP_HOST}/$1$2/ [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM