www htaccess redirect with segment in url

1

Where my site is hosted, I'm using .htaccess and it has a condition to remove the www and direct to the main page, without the www.

<ifModule mod_rewrite.c>

Header set X-Frame-Options DENY

RewriteEngine On

# Required to allow direct-linking of pages so they can be processed by Angular
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule (.*) http://meusite.com.br [R=301,L]

</ifModule>

The problem is this, when someone accesses an internal page with www, it falls for this check and is directed to the home, eg:

If someone accesses the link: link

It will direct you to link under the condition.

What I need is to be directed to the following link: link just by removing the www from the link.

Does anyone know if this check is possible in .htaccess?

Remembering that when I access the internal with www, I need to remove only the www and not be redirected to the home.

    
asked by anonymous 19.06.2017 / 22:43

1 answer

1
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Font

    
19.06.2017 / 22:48