0

是否可以重写网址,例如:

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

至:

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

到目前为止我所拥有的:

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
4

1 回答 1

1

尝试这个:

<IfModule mod_rewrite.c>

  Options +FollowSymLinks
  RewriteEngine On
  RewriteBase /

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

</IfModule>

笔记:

fr在那里添加,以便您可以看到多种语言的示例。此外,这将是对 index.php 脚本的内部重定向。

编辑:

修改为现在允许在 URI 的语言部分之后添加内容。现在应该如何工作。

这是正则表达式的一个很好的参考:

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

于 2012-06-13T14:53:51.140 回答