1
我的.htaccess目前的样子:不需要的index.php从example.com/{lang}/index.php
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]
这意味着example.com/{lang}/some-page.php
作为example.com/some-page.php?lang={lang}
剩下的问题:example.com/{lang}
做不工作,除非它有index.php
like`example.com/{lang}/index.php
当我们直接去example.com/{lang}
时,我该如何使它工作?
没有2个字母的文件/目录,所以我们可以省略。使用你的规则,但是当我去'example.com/xx',我得到一个404 –
我删除了检查。你把它放在根.htaccess文件中? – SuperDuperApps
我添加了检查以避免循环。 – SuperDuperApps