微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

结合“文件夹作为GET参数”和“子域作为GET参数”

我有一个网站,重写域后的pathpage GET参数。

##rewriting DIRECTORIES TO GET ParaMETERS RewriteBase / #Ignore all real directories (do not rewrite them) RewriteCond %{REQUEST_FILENAME} !-d #Also do not rewrite real files RewriteCond %{REQUEST_FILENAME} !-f #For everything else,index.PHP should fetch the proper content RewriteRule ^([^/]*)$ index.PHP?page=$1 [QSA,L] ##This means: #example.com/help #~becomes~ #example.com?page=help

该网站使用多种语言,到目前为止,我一直在使用cookie设置和记住用户的语言。 虽然用户的方便是有争议的,这绝对不方便的search引擎优化 。

我需要将[az]{2}.mydomain.xx为index.PHP?lang=$1以便用户始终位于en.domain.com上。 有这样的例子,但是我仍然对重写引擎的工作方式感到困惑,我不知道我应该如何将新规则与旧规则结合起来:

##Language rewrite #copypasted. Didn't understand RewriteCond %{HTTP_HOST} ^([az]{1,2}).domain.xx RewriteRule ([az]{1,2}).domain.xx index.PHP?lang=$1 [QSA,L]

如何获得en.domain.com/help转到index.PHP?page=help&lang=en ?

Apache + Python Bottle:访客IP总是指127.0.0.1

在.htaccess中为带有后缀的所有url设置redirect

MVC htaccess重写

.htaccess:如何限制IP访问单个文件

htaccess用mod_GeoIP重写规则

.htaccess无法parsing根文件夹中的HTML文件中的PHP

.htaccess子文件

htaccess根据主机名或域名重写

.htaccess用get参数重写url

用mod_rewrite重写PHP中的URL

如何获取en.domain.com/help转到index.PHP?page = help&lang = en

您可以使用:

RewriteEngine On RewriteBase / #Ignore all real directories (do not rewrite them) RewriteCond %{REQUEST_FILENAME} !-d #Also do not rewrite real files RewriteCond %{REQUEST_FILENAME} !-f #For everything else,index.PHP should fetch the proper content RewriteCond %{HTTP_HOST} ^([az]{1,2}).domain.xx$ [NC] RewriteRule ^([^/]+)/?$ index.PHP?lang=%1&page=$2 [QSA,L]

参考: Apache mod_rewrite介绍

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐