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.)

Let me explain, our situation is this:

Read More

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!

Related posts

Leave a Reply

1 comment

  1. 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]