我想解决下一个问题:
1)当输入没有语言的url时,使用英语作为默认示例:
http//localhost/plants/或http//localhost/plants
或
http//localhost/工厂/商店/配件
2)当使用语言输入url时,将该参数作为使用示例的语言传递:
http//localhost/核电厂/es/shop/配饰
或
http//localhost/plants/es/或http//localhost/plants/es
到目前为止,我已经尝试过:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(en|es)/(.*)$ index.php?url=$2&lang=$1 [L,QSA]
RewriteRule ^(.*)$ index.php?url=$1&lang=en [L,QSA]如果我注释第一个RewriteRule并输入任何url,它可以正常工作,但始终使用en语言。
如果我评论第二个RewriteRule,并在语言中使用url:
http//localhost/plants/es/
或
http//localhost/核电厂/es/shop/配饰
它工作得很好,但它不设置默认语言为英语时,没有给出。
你知道当我离开这两条规则的时候为什么不起作用吗?
谢谢
Ps:我已经删除了http之后的:
发布于 2015-10-14 18:33:13
如果plants是您的文档根,则应该能够使用此规则。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !/(en|es)
RewriteRule ^(.*)/?$ index.php?url=$1&lang=en [L,QSA]
RewriteRule ^(en|es)/?(.*)/?$ index.php?url=$2&lang=$1 [L,QSA]让我知道它是如何为你工作的。
发布于 2015-10-14 18:14:35
将以下htaccess文件放入/plants目录中:
RewriteEngine On
RewriteBase /plants
RewriteCond %{REQUEST_URI} !^/plants/e[ns](/|$) [NC]
RewriteCond %{QUERY_STRING} !lang=e[ns] [NC]
RewriteRule ^.*$ /plants/en/$0 [R=301,L]
RewriteRule ^(e[ns])/(.*)$ index.php?url=$2&lang=$1 [NC,L,QSA]如果上述方法仍然不起作用,请更新您自己的方法,如下所示:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteRule ^(en|es)/(.*)$ index.php?url=$2&lang=$1 [L,QSA]
RewriteRule ^(.*)$ index.php?url=$1&lang=en [L,QSA]发布于 2015-10-14 18:15:56
找到了这样的解决方案:
RewriteEngine打开 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(en=es)/(.*)$ index.php?url=$2&lang=$1 L,QSA RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.*)$ index.php?url=$1&lang=en L,QSA
我怎样才能改善这一点?感觉很不对劲,我不得不用同样的时间写两遍
https://stackoverflow.com/questions/33132246
复制相似问题