简体   繁体   English

.htaccess mod_rewrite与语言选择器

[英].htaccess mod_rewrite with language selector

Is it possible to rewrite urls such as: 是否可以重写网址,例如:

http://www.domain.com/?language=en
http://www.domain.com/contact?language=en

to: 至:

http://www.domain.com/en/
http://www.domain.com/en/contact

What I have so far: 到目前为止,我有:

RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?language=$1 [QSA,L]

http://www.domain.com/en/ <- Gives a server not found error
http://www.domain.com/en/contact <- Goes to the main root (/index.php) and give the en variable

Try this: 尝试这个:

<IfModule mod_rewrite.c>

  Options +FollowSymLinks
  RewriteEngine On
  RewriteBase /

  RewriteRule ^(en|fr)(/(.*))$ $2/index.php?language=$1 [L]

</IfModule>

Note: 注意:

I added fr in there so that you could see an example of multiple languages. 我在其中添加了fr ,以便您可以看到多种语言的示例。 Also, this will be an internal redirect to the index.php script. 另外,这将是内部重定向到index.php脚本。

Edit: 编辑:

Revised to now allow for stuff after the language part of the URI. 修改为现在允许URI语言部分之后的内容。 Should work how you want it now. 应该现在就按您想要的方式工作。

Here's a good reference for Regular Expressions: 这是正则表达式的一个很好的参考:

http://www.regular-expressions.info/reference.html http://www.regular-expressions.info/reference.html

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

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