Redirect 301 adding many "/" s at the end

0

I'm facing the following problem with a combination of more than .htaccess in my project.

I have the following structure

siteprincipal.com.br (não é WordPress)

and inside a subdomain with another WordPress site

site2.siteprincipal.com.br

site2 is inside a directory in public_html , where the main site runs

I have two .htaccess in the following structure

public_html (siteprincipal)
|--.htaccess
|--site2 (wordpress)
   |--.htaccess

When I make a redirect of a url from siteprincipal to site2 , like for example

Redirect 301 /paginainterna/ http://site2.siteprincipal.com.br/paginainterna

the end result is

http://site2.siteprincipal.com.br/paginainterna////////////////

which results in an incorrect redirect.

content .htaccess of siteprincipal is

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

Redirect 301 /paginainterna/ http://site2.siteprincipal.com.br/paginainterna

#redirect sempre para www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php

RewriteRule .* index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

and .htaccess of site2 is the default for WordPress

# BEGIN WordPress
AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

How can I prevent this "/" from being included, or what I am doing wrong?

    
asked by anonymous 12.10.2015 / 17:40

1 answer

1

In this type of structure, the first .htaccess manages both the calls to the main domain and the subdomain.

Note that the two pages have the same address, for example:

www.siteprincipal.com.br/page1 

and

site2.siteprincipal.com.br/page1

The redirect will loop because the first .htaccess will send to the subdomain and attempt to redirect again because it is only based on %{REQUEST_URI} .

So it's important not to do a redirect using

Redirect 301 /page1 http://site2.siteprincipal.com.br/page1

and yes

RewriteCond %{HTTP_HOST} !^www\.siteprincipal\.com\.br$ [NC]
RewriteCond %{REQUEST_URI} !^\/page1$ [NC]
RewriteRule . http://site2.siteprincipal.com.br%{REQUEST_URI} [R=301,L]

This ensures that the redirect reaches only the call made directly to siteprincipal and not to the subdomain.

    
14.10.2015 / 03:20