简体   繁体   English

htaccess将根目录重定向到子目录,但允许根目录中的index.php和查询字符串起作用

[英]htaccess redirect root to subdirectory but allow index.php in root AND query strings to function

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.) (用户“ anubhava”能够回答原始问题。)

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). 我们正在使用Joomla启动一个新网站,但是,我们希望所有旧网站的入站链接都能继续运行(因为我们在旧网站上的WordPress中有很多内容)。 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. 因此,使用htaccess,我们能够将对主域名的所有请求重定向到其中包含新Joomla网站的子目录。 [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.] [因此,例如,由于需要htaccess代码,因此对www.example.com的请求将重定向到www.example.com/PORTALsite。

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). 此外,此代码还允许对旧WordPress网站首页的请求仍然有效(我们正在替换的旧网站)。 [So as an example, www.example.com/index.php will still function and load the old WordPress site, which is what we want.] [因此,例如,www.example.com / index.php仍然可以运行并加载旧的WordPress网站,这正是我们想要的。]

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. 仅当请求仅针对域名(www.example.com)时,它才会重定向到新的Joomla网站的主页(位于www.example.com/PORTALsite/),但如果请求是针对旧网站的主页页面(位于www.example.com/index.php),它将允许此操作并加载旧的WordPress网站。

Here's the htaccess code: 这是htaccess代码:

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). 但是,我现在的问题是 :有很多入站链接,其中省略了旧WordPress网站的index.php页面,并且仅附加了查询字符串(指示通过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. 但是,由于上面的代码将其视为仅对主域名的调用(因为它“忽略”了查询字符串),因此它也将其重定向到新的Joomla网站。 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. (不是问题)对主域名的请求已成功重定向到新的Jooma网站,因此www.example.com将根据我们的需要和重定向到www.example.com/PORTALsite。

  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. (不是问题)www.example.com/index.php可以按照我们的需要和应有的方式成功加载旧WordPress网站的主页。

  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. 但是,这是问题所在 :没有文件名但包含查询字符串的入站链接(例如www.example.com/?page_id=56)也将重定向到新的Joomla网站(例如,www.example。 com / PORTALsite /?page_id = 56),我们希望发生这种情况。

    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. 我们希望www.example.com/?page_id=56重定向到www.example.com/index.php?page_id=56并从旧的WordPress网站加载内容。 how do I make this happen based upon the htaccess code above? 如何根据上面的htaccess代码实现此目标?

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]

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

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