htaccess的重定向根子目录,但允许的index.php根,查询字符串的功能 [英] htaccess redirect root to subdirectory but allow index.php in root AND query strings to function

查看:139
本文介绍了htaccess的重定向根子目录,但允许的index.php根,查询字符串的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似的问题,这是回答。然而,答案引发了另外一个概念,现在我有以下问题。 (网友anubhava能回答原来的问题。)

让我来解释一下,我们的情况是这样的:

我们正在推出使用Joomla,但是,我们希望所有的旧网站的入站链接来继续工作(因为我们有很多内容在Word preSS旧网站)一个新的网站。因此,使用htaccess的,我们能够具有的所有请求到主域名重定向到一个子目录与新的Joomla网站中它。 [所以,作为一个例子,由于htaccess的code,这是我们所希望的要求为www.example.com重定向到www.example.com/PORTALsite。]

此外,该code还允许仍然函数(旧网站,我们正在更换)请求老字preSS网站的主页。 [所以,作为一个例子,www.example.com/index.php仍将正常并加载旧的Word preSS网站,这是我们想要的。]

只有当请求的域名独(www.example.com),将其重定向到新的Joomla网站的主页(位于www.example.com/PORTALsite/),但是如果请求是针对旧网站的主页(位于www.example.com/index.php),它将使这一点,并加载旧的Word preSS的网站。

下面是htaccess的code:

  RewriteEngine叙述上
的RewriteCond%{THE_REQUEST} ^ [A-Z] {3,} \ S / + \ S?]
重写规则^ $ / PORTALsite [R = 301,L]
 

但是,我现在的问题是这样的:有很多入境环节,其中老字preSS网站的index.php页面被省略,只查询字符串连接(指示经由字preSS旧网站的页面名称)。但是,因为code以上认为这是一个电话只是单独的主域名(因为它忽略的查询字符串),它也重定向这对全新的Joomla网站。 我们不希望这种情况发生!任何帮助,请?

的例子是什么问题,现在

    对于主域名
  1. (没有问题),请求被成功重定向 新Jooma网站,从而www.example.com重定向到 www.example.com/PORTALsite,因为我们希望并作为它应该。

  2. (没有问题),www.example.com/index.php~~MD成功加载了旧的Word preSS 网站的首页虽然,因为我们要和它应该。

  3. 但是这是问题:在绑定没有文件名,但包括一个链接 查询字符串,如www.example.com/?page_id=56也越来越 重定向到新的Joomla网站(例如,www.example.com/PORTALsite/?page_id=56),我们DO 不会希望这种事情发生。

    我们希望www.example.com/?page_id=56重定向到 www.example.com/index.php?page_id=56并加载从内容 旧的Word preSS网站。 如何使基于htaccess的code以上出现这种情况?

在此先感谢您的帮助!

解决方案

  RewriteEngine叙述上
#匹配请求/
的RewriteCond%{THE_REQUEST} ^ [A-Z] {3,} \ S / + \ S?]
#不匹配的请求PAGE_ID = N
的RewriteCond%{QUERY_STRING}!PAGE_ID = [0-9] +
#重定向到/ PORTALsite
重写规则^ $ / PORTALsite [R = 301,L]
 

I had a question similar to this, and it was answered. However, the answer led to another concept and now I have the following question. (User "anubhava" was able to answer the original question.)

Let me explain, our situation is this:

We are launching a new website using Joomla, however, we wanted all of the old website's in-bound links to continue to function (as we have a lot of content in WordPress on the old website). So, using htaccess, we were able to have all requests to the primary domain name redirect to a sub-directory with the new Joomla website in it. [So as an example, requests for www.example.com get redirected to www.example.com/PORTALsite due to the htaccess code, which is what we want.]

Further, this code also allows for requests to the Home page of the old WordPress website to still function (the old website we are replacing). [So as an example, www.example.com/index.php will still function and load the old WordPress site, which is what we want.]

Only if the request is for the domain name alone (www.example.com) will it redirect to the new Joomla website's Home page (located at www.example.com/PORTALsite/), but if the request is for the old website's Home page (located at www.example.com/index.php) it will allow this and load the old WordPress website.

Here's the htaccess code:

RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+[\s?]
RewriteRule ^$ /PORTALsite [R=301,L]

HOWEVER, my problem now is this: There are many in-bound links where the old WordPress website's index.php page is omitted and only a query string is attached (indicating a Page name on the old website via WordPress). However, because the code above sees this as a call just to the primary domain name alone (as it "ignores" the query string) it also redirects this to the new Joomla website. We do not want this to happen! Any help, please?

Example of what the problem is now:

  1. (not a problem) requests for the primary domain name are successfully redirected to the new Jooma website, thus www.example.com will redirect to www.example.com/PORTALsite, as we want and as it should.

  2. (not a problem) www.example.com/index.php successfully loads the old WordPress website's Home page though, as we want and as it should.

  3. however this is the problem: in-bound links that have no file name but include a query string, such as www.example.com/?page_id=56 are also getting redirected to the new Joomla website (for example, www.example.com/PORTALsite/?page_id=56) AND WE DO NOT WANT THIS TO HAPPEN.

    we want www.example.com/?page_id=56 to redirect to www.example.com/index.php?page_id=56 and load the content from the old WordPress site. how do I make this happen based upon the htaccess code above?

Thanks in advance for any help!

解决方案

RewriteEngine on
# Match requests for /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+[\s?]
# Don't match requests for page_id=n
RewriteCond %{QUERY_STRING} !page_id=[0-9]+
# Redirect to /PORTALsite
RewriteRule ^$ /PORTALsite [R=301,L]

这篇关于htaccess的重定向根子目录,但允许的index.php根,查询字符串的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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