Redirect any html extension URL to a specific page

0

Please, I have a question in .htaccess (or apache).

I need to redirect any url containing .html or .htm extension to a specific url. Example:

  • domain.com/test.html - > domain.com/page
  • domain.com/teste123.htm - > domain.com/page

Follow the current .htacces:

# BEGIN WordPress
<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

Thanks for the help.

    
asked by anonymous 04.09.2015 / 00:55

1 answer

1

For this redirection it is necessary to have the mod_rewrite module turned on. To turn it on, use this command:

sudo a2enmod rewrite
sudo service apache2 restart # para reiniciar o servidor

Inserts the following content in .htaccess :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^pagina$ - [L] 
RewriteRule ^(.*)\.html?$ pagina [L] 

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

Note: For this to work, you must have the AllowOverride All option in the current vhost directory setting ( <Directory>...</Directory> ).

    
04.09.2015 / 02:45