search

Home  >  Q&A  >  body text

Why does my URL remove "wp-content" after redirecting from the root domain to a subdomain?

My test URL is: https://mydomains.com/wp-content/uploads-webpc/uploads/2022/05/store-riil-x-1-300x404.jpg.webp

My htaccess rules are as follows:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^mydomains\.com [NC]

RewriteRule ^(.*)$ https://www.mydomains.com/ [L,R=301]

When I test the rules in https://htaccess.madewithlove.com/, the results are as follows:

  1. RewriteCond %{HTTP_HOST} ^aspirecig\.com$ [NC]

    Meet this condition.

  2. RewriteRule ^(.*)$ https://www.aspirecig.com/$1[L,R=301]

    The new URL is https://www.aspirecig.com/wp-content/uploads-webpc/uploads/2022/12/black-1.jpg.webp

    Testing has stopped and will be redirected with status code 301

The browser's url is actually rewritten to: https://www.mydomains.com/uploads-webpc/uploads/2022/05/store-riil-x-1-300x404.jpg.webp

Why am I missing "wp-content"? What are the possible reasons for this? Can anyone help me? Thank you so much

P粉098979048P粉098979048318 days ago411

reply all(1)I'll reply

  • P粉446800329

    P粉4468003292024-01-18 00:25:23

    When you use a RewriteRule in .htaccess (or ), some of the leading parts on the strings you are implicitly comparing are removed.

    In DocumentRoot, it is the leading "/". A directory deeper, such as wp-content/ in the document root, it will also delete the directory that led you there.

    So if this htaccess is in $docroot/wp-content, /wp-content will be removed. If you want to return the full original URL, avoid $1 here and use %{REQUEST_URI}.

    reply
    0
  • Cancelreply