有条件的.htaccess(Conditional .htaccess)

   IT问题网   2019-04-23 00:00:00

问 题

我敢肯定有类似主题的其他线程各地的网络,但我不能得到这个工作对我自己的网站。

现在的问题是,我有一个多语种网站,所选择的语言是通过url来控制。现在的网址是:

www.website.com/en/order
 

或任何英语或

www.website.com/da/order
 

丹麦。这是所有工作得很好,但是我希望能够只使用了普通的url为默认语言,例如 www.website.com/order 它会再只需选择默认语言(我在我的php code定义)。

有没有简单的方法来做到这一点使用的.htaccess?现在我的.htaccess code是如下:

 重写规则^(。*)1 \ / $的index.php lang = $&amp(*);?页= $ 2 [nc]
 

我也试过有两条规则:

 重写规则^(。*)1 \ / $的index.php lang = $&amp(*);?页= $ 2 [nc]
重写规则^(。*)$的index.php?网页= $ 1 [nc]
 

但没有任何工程。

解决方案

这应该赶不以2字母语言code开始,并简单地重写所有那些做的所有网址,的index.php

 的rewritecond%{request_uri}!^ / [az] {2} / [nc]
重写规则^(。*)$的index.php?网页= $ 1 [qsa,l]

#匹配那些确实有一个语言code
重写规则^([az] {2})1 / $的index.php lang = $&amp(*);?页= $ 2 [qsa,l,nc]
 

当然,你要确保你没有同时也是2个字母的组合...

任何网页网址

如果你只有一小部分语言支持(如"阿凡达","恩","德"),你可以通过做而不是使用这个更强大的

 的rewritecond%{request_uri} ^ /!(da | zh | de)/ [nc]
 

顺便说一句,你要永远记住使用qsa标志追加任何现有的get paramters到重写url。

标签:有条件



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

重定向的站点根目录使用的.htaccess子目录(Redirecting root of site to subdirectory using .htaccess)

problem a site of mine has all the files stored in a subd ...

的.htaccess URL重写 - 删除的.php去除WWW。转换?ID = 10/10(.htaccess url rewrite - remove .php remove www. convert id=10 to /10)

problem as the title says, i need a quite com ...

从Symfony的1.4路径删除“网络”共享托管?(Remove 'web' from Symfony 1.4 path on shared hosting)

problem i've found a lot of helpful information about ins ...

小问题.htaccess文件?(small problem with .htaccess file)

problem i have a small .htaccess file which allow me to r ...

的.htaccess基于查询字符串重定向和删除查询字符串(.htaccess redirect based on query string and remove query string)

problem i'm in need to have redirect instruct ...

htaccess的导致服务器错误500(htaccess causing server error 500)

problem i have a zend framework application w ...

404 htaccess的重定向不工作(404 htaccess redirect is not working)

problem i am running tomcat on apache we server. i am put ...

通过重定向某些变量的任何页面(Redirect any page passing certain variables)

problem i'm putting a search engine on my site, and the s ...

与RewriteMap指令的MapType DBD问题(Problems with RewriteMap MapType dbd)

problem continuing from another discussion he ...

重写URL时,一个表单提交(rewrite url when a form is submitted)

problem question regarding redirection using htaccess. on ...

从URL preventing直接访问(Preventing direct access from url)

problem in one of my work i need to build a feature for u ...

的.htaccess不会影响到其他文件夹(.htaccess not affecting other folders)

problem i have a .htaccess file that affects my subdomain ...

mod_rewrite的错误:[客户127.0.0.1]文件不存在(mod_rewrite error: [client 127.0.0.1] File does not exist)

problem i want to start using mod_rewrite so i can use fr ...

重写全球htpasswd的密码保护(Overriding global htpasswd password protection)

problem i am testing a drupal site on a development serve ...

PHP路径包含文件(PHP Path to Include Files)

problem i have a site with an index.php. the index.php ha ...

重写URL隐藏的index.php并作出查询不错(Rewriting url to hide index.php and to make query nice)

problem i had developed project with custom mvc architect ...

htaccess的URL路由的PHP MVC?(htaccess URL routing for PHP MVC)

problem i've been searching and have yet to find an artic ...

的.htaccess规则相应的HTTP链接,HTTP和HTTPS重定向到HTTPS?(.Htaccess rules to redirect respective HTTP links to HTTP and HTTPS to HTTPS)

problem first, here's the .htaccess rule i cu ...

使用的.htaccess追加html的URL路径的背后(using .htaccess to append .html behind url path)

problem people are coming into my website like this: sit ...

的.htaccess迫使对SSL错误页面(.htaccess forcing error pages on SSL)

problem i have the following piece of code in ...