• Resolved leocalbusch

    (@leocalbusch)


    Hello

    I set up multiple domains on a hosting server, each domain pointing to a subfolder via htaccess.

    i.e.:

    
    # for domain1
    RewriteCond %{HTTP_HOST} domain1.com [NC]
    RewriteCond %{REQUEST_URI} !^/domain1
    RewriteRule ^(.*)$ /domain1/$1 [L]
    
    # for domain2
    RewriteCond %{HTTP_HOST} domain2.com [NC]
    RewriteCond %{REQUEST_URI} !^/domain2
    RewriteRule ^(.*)$ /domain2/$1 [L]
    

    I have installed WP in one of that subfolders, and now the url automatically is set to domain1/domain1/, duplicating the domain. How can I get rid of that?

Viewing 4 replies - 1 through 4 (of 4 total)
  • WordPress does not create this htaccess, however if you have to use two wordpress installations with different folders you have to combine the rule. If this rule is created by a plugin or theme, make sure you ask them for support or you will have to set it manually each time you update.

    Correct for multiple domain name

    # for domain1 and domain2
    # for root
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} domain(1|2).com [NC]
    RewriteCond %{REQUEST_URI} !^/(domain1) [NC,OR]
    RewriteCond %{REQUEST_URI} !^/(domain2) [NC]
    RewriteRule ^/?(domain(1|2))?(.*)$ /%2/$3 [L]

    Internal redirect.
    $1 your script is domain1 o domain2
    /domain1/domain1
    My script if folder not domain1 and not domain2 default is folders domain2, RewriteRule work with start domain1 or domain2 else all value.

    Thread Starter leocalbusch

    (@leocalbusch)

    Thank you @autotutorial ! What I have is exactly that, multiple websites under the same hosting server account. That’s why I need to redirect each domain to its subdirectory. The htaccess I`ve mencioned is at my root folder, so each requisition is redirected to its correspondent subdirectory. What is happening is that once I have installed WP in one of the subdirectories, when I open the website the url is set to domain/subdirectory and I don’t know why. I.e.:

    I have the htaccess in root, I copy the WP files into the subdirectory and install it. Inside wp folder we have its htaccess as well. The url for my admin panel is right, mydomain/wp-admin. However, when I access the website, the url turns to mydomain/subdirectory.

    If I don’t install wp and simply put any html, the subdirectory don’t appear in the url.

    I hope you can understand this mess ??

    • This reply was modified 5 years, 4 months ago by leocalbusch.
    • This reply was modified 5 years, 4 months ago by leocalbusch.

    sorry I wrote a wrong code, as per wordoress manual do a redirect based on whether your domain is identified if it is a different path that is not files and no directories redirect with all the content otherwise redirect to your index folder. php. In this scenario you must also include a redirect to the default domain if it does not match any rules.

    # for domain1 and domain2
    # for root
    #Fix wordpress
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^(www.)?domain1.example.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/my_subdir1/ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /my_subdir1/$1 [L]
    RewriteCond %{HTTP_HOST} ^(www.)?domain1.example.com$ [NC]
    RewriteRule ^(/)?$ my_subdir1/index.php [L]
    RewriteCond %{HTTP_HOST} ^(www.)?domain2.example.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/my_subdir2/ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /my_subdir2/$1 [L]
    RewriteCond %{HTTP_HOST} ^(www.)?domain2.example.com$ [NC]
    RewriteRule ^(/)?$ my_subdir2/index.php [L]
    #Default Domain
    RewriteCond %{HTTP_HOST} !^(www.)?domain1.example.com$ [NC]
    RwwriteCond %{HTTP_HOST} !^(www.)?domain2.example.com$ [NC]
    RewriteRule ^(/)?$ https://domain1.example.com/my_subdir1/index.php [R,L]
    </IfModule>

    PT

    Thread Starter leocalbusch

    (@leocalbusch)

    Thank you, that was very helpful!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘URL and subfolders’ is closed to new replies.