[英]Not needing index.php from example.com/{lang}/index.php
My .htaccess currently looks like:我的 .htaccess 目前看起来像:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+([^/]+)/\?lang=([^\s&]+) [NC]
RewriteRule ^ /%2/%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]{2})/([^/]+)/?$ $2/?lang=$1 [L,QSA]
Which means that example.com/{lang}/some-page.php
acts as example.com/some-page.php?lang={lang}
这意味着
example.com/{lang}/some-page.php
充当example.com/some-page.php?lang={lang}
Remaining issue: example.com/{lang}
does not work unless it has index.php
like `example.com/{lang}/index.php剩下的问题:
example.com/{lang}
不起作用,除非它有index.php
像 `example.com/{lang}/index.php
How can I make it work when we go directly to example.com/{lang}
?当我们直接访问
example.com/{lang}
时,如何使其工作?
How about this:这个怎么样:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_rewritten} !=1
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2})$ [NC]
RewriteRule ^([^/]*)$ /%1/$1? [R=301,L]
RewriteCond %{REQUEST_URI} !^/js/
RewriteRule ^([a-z]{2})(?:/([^/]+))?$ $2?lang=$1 [NC,L,QSA,E=rewritten:1]
I really don't like matching on THE_REQUEST so changed that.我真的不喜欢在 THE_REQUEST 上匹配所以改变了它。 This also redirects just
/?lang=xx
which you may not want.这也仅重定向了您可能不想要的
/?lang=xx
。 I used the same matching for lang strings in both rules which you may not want.我在您可能不想要的两个规则中对 lang 字符串使用了相同的匹配。 Let me know.
让我知道。
Not sure you need the file or directory existence checks and it is slowing things down a bit if not necessary, as the filesystem must be polled twice on every request.不确定您是否需要检查文件或目录是否存在,如果没有必要,它会减慢速度,因为每次请求都必须轮询文件系统两次。 Do you have two letter files or directories in root?
根目录下是否有两个字母文件或目录?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.