结合"文件夹GET参数"和"子域中GET参数" [英] Combine "folder as GET parameter" and "subdomain as GET parameter"

查看:184
本文介绍了结合"文件夹GET参数"和"子域中GET参数"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,域名,重写到页路径 GET参数。

  ##改写目录找到参数
的RewriteBase /
#Ignore所有真正的目录(不重写它们)
的RewriteCond%{} REQUEST_FILENAME!-d
#Also不重写真正的文件
的RewriteCond%{} REQUEST_FILENAME!-f
#For一切,index.php文件应取适当的内容
重写规则^([^ /] *)$的index.php?网页= $ 1 [QSA,L]

##意即:
#example.com /帮助
#〜变为〜
#example.com?页=帮助
 

该网站使用多种语言,到目前为止,我一直在使用Cookie来设置并记住用户的语言。虽然用户的便利性是有争议的,这绝对不是方便了 SEO

我需要重写 [AZ] {2} \。MYDOMAIN \ .XX 的index.php?LANG = $ 1 ,以便用户将始终 en.domain.com 为例。有例子要做到这一点,但是我仍然感到困惑如何重写引擎的工作原理,我不知道我应该如何结合自己的新规则与旧的:

  ##语言重写
#Copypasted。没看懂
的RewriteCond%{HTTP_HOST} ^(即[az] {1,2})\域\ .XX
重写规则(即[az] {1,2})\域\ .XX的index.php?LANG = $ 1 [QSA,L]
 

我怎样才能获得 en.domain.com/help 转折 index.php页面=帮助和放大器; LANG = EN

解决方案
  

我怎样才能得到en.domain.com/help转折index.php页面=帮助和放大器; LANG = EN

您可以使用:

  RewriteEngine叙述上
的RewriteBase /

#Ignore所有真正的目录(不重写它们)
的RewriteCond%{} REQUEST_FILENAME!-d
#Also不重写真正的文件
的RewriteCond%{} REQUEST_FILENAME!-f
#For一切,index.php文件应取适当的内容
的RewriteCond%{HTTP_HOST} ^(即[az] {1,2})\域\ .XX $ [NC]
?重写规则^([^ /] +)/ $的index.php LANG =%1安培;页= $ 2 [QSA,L]
 

参考: URL重写简介

I have a site that rewrites path after domain to a page GET parameter.

##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

The site uses multiple languages and so far, I've been using cookies to set and remember the language for the user. While the convenience for the user is disputable, this is definitely not convenient for the SEO.

I need to rewrite [a-z]{2}\.mydomain\.xx to index.php?lang=$1 so that user will be always on en.domain.com for example. There are examples to do this, however I'm still confused about how the rewrite engine works and I don't know how should I combine my new rules with the old ones:

##Language rewrite
#Copypasted. Didn't understand
RewriteCond %{HTTP_HOST} ^([a-z]{1,2})\.domain\.xx
RewriteRule ([a-z]{1,2})\.domain\.xx index.php?lang=$1 [QSA,L]

How can I get en.domain.com/help turn in index.php?page=help&lang=en?

解决方案

How can I get en.domain.com/help turn in index.php?page=help&lang=en

You can use:

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} ^([a-z]{1,2})\.domain\.xx$ [NC]
RewriteRule ^([^/]+)/?$ index.php?lang=%1&page=$2 [QSA,L]

Reference: Apache mod_rewrite Introduction

这篇关于结合"文件夹GET参数"和"子域中GET参数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆