Redirect 301 adding many "/"s at the end

Asked

Viewed 71 times

0

I am facing the following problem with the combination of more than one .htaccess in my project.

I have the following structure

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

and inside a domain with another site in Wordpress

site2.siteprincipal.com.br

site2 is inside a directory on public_html, where the main website runs

have two .htaccess in the following structure

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

when I make a redirect of a url of siteprincipal to the site2, as an example

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

the final result is

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

which results in an incorrect redirect.

the 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 the .htaccess of site2 is the standard of 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 I can prevent this lot of "/" from being included, or what I’m doing wrong?

1 answer

1


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

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

www.siteprincipal.com.br/page1 

and

site2.siteprincipal.com.br/page1

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

so it is important not to make 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 way ensures that the redirect reaches only the call made directly to the siteprincipal and not to the subdomain.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.