• Resolved Irene

    (@arlinaite)


    My site structure is main site “mysite” and two subfolders sites /es/ and /en/

    mysite.com redirects => mysite.com/es/

    What is wrong: mysite/non-existing-page redirects => mysite.com/es/
    Some part of this main redirect is causing that every non-existing page inside mysite.com (This site is empty) is redirected to the main page which is in the subdomain mysite.com/es/ instead of getting a 404 error. I see where is the problem but I don’t know how to modified the rule

    My redirect in the htaccess file:

    # Main Redirect
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^mysite\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
    RewriteRule ^/?$ "https\:\/\/mysite\.com\/es\/" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^mysite\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
    RewriteRule ^index\.html$ "https\:\/\/mysite\.com\/es\/" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^mysite\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
    RewriteRule ^indexingles\.html$ "https\:\/\/mysite\.com\/en\/" [R=301,L]

    Works perfect for the following:
    Is perfect that mysite.com/ redirects => mysite.com/es
    Is perfect that index.html redirects => mysite.com/es
    Is perfect that indexingles.html redirects => mysite.com/en

    Summarizing

    Every URL that has mysite.com/non-existen-page redirects to the main page: mysite.com/es/. Its a very bad thing that it doesn’t get a 404 error. I have to change this and I don’t know how .

    If the URL is mysite.com/es/non-existen-page it gets a 404 error which is ok.

    If the URL is mysite.com/en/non-existen-page it gets a 404 error which is ok.

    Thanks in advance

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    The idea is any request to the main domain should be redirected to /es/, right? If it’s a bad request, it should then 404 in the /es/ site. For that to work, the bad request has to be passed to /es/. Try replacing the first RewriteRule line with this:
    RewriteRule (.*) https://mysite.com/es/$1 [R=301,L]

    (you only need to escape special chars in regexps. The destination URL is not a regexp)

    Thread Starter Irene

    (@arlinaite)

    Ok thanks! I will try this when I have low traffic and I will come back with the answer.

    Thread Starter Irene

    (@arlinaite)

    Sorry but the code provided cause an error of too many redirects

    • This reply was modified 4 years, 1 month ago by Irene.
    Moderator bcworkz

    (@bcworkz)

    Ah, sorry about that. We need another RewriteCond to not rewrite if it has already been rewritten. After RewriteEngine On, insert:
    RewriteCond %{REQUEST_URI} !^/es/

    Do you have other domains or sub-domains landing in the same directory? If not, I’d think

    RewriteCond %{HTTP_HOST} ^mysite\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.mysite\.com$

    would be unnecessary since it’d always be one or the other. But then, “If it ain’t broke, don’t fix it” ??

    Thread Starter Irene

    (@arlinaite)

    Ok, thanks!!! I deleted some code that was before, I applied the changes and it worked.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Multisite redirect issue’ is closed to new replies.