Redirect www htaccess with segment in url

Asked

Viewed 198 times

0

Where my site is hosted, I am using the . htaccess and on 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, example:

If someone accesses the link: http://www.meusitecom.br/conteudo/94-vai-criar-um-site-para-a-sua-empresa-saiba-o-que-nao-pode-faltar

It will direct to http://meusite.com.br as per condition.

What I need is to be directed to the following link: http://meusitecom.br/conteudo/94-vai-criar-um-site-para-a-sua-empresa-saiba-o-que-nao-pode-faltar just removing the www from the link.

Does anyone know if there is a possibility of this verification being done in . htaccess?

Remembering that when accessing the internal with www, need to be removed only www and not redirected to the home.

1 answer

1


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

Source

  • It didn’t work :/ I edited the question and entered the whole . htaccess code

  • @Mauríciokrüger is sure? I took the test and it worked. Test link

Browser other questions tagged

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