Kevin Gobert Kevin Gobert - 5 months ago 22
PHP Question

.htaccess combine 2 RewriteRule

I have a small question .htaccess perspective.

I urls from the old site which is composed as follows:

news- pecq_mur_quai_plateforme_bimodale_dechargement_inauguration_escaut.html


these URLs become :
pecq_mur_quai_plateforme_bimodale_dechargement_inauguration_escaut


I have to delete 'news-' and '.html' of these urls .

I have combined two rules and I do not see how. Here's my start code .

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news-(.*)$ /$1 [L,R=301]
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
</IfModule>

Answer

You can remove both perms from your url using a single rule, try :

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news-(.*?)\.html$ /$1 [L,R=301]

Clear your browser cache before testing this redirect.