1

I'trying to write a regex that matches an url with and without html, Itried this way but ots not working

RedirectMatch 301 ^/my_url(\.html)$ /es/promo/my_url.html

It shoul work for myurl and my_url.html but it doesn't

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
a_cl
  • 101
  • 1
  • 4

2 Answers2

0

Could you please try following, written and tested as per shown samples. This will rewrite every non existing file and non existing directory to respective html in backend to be served. Please make sure you clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/my_url [NC]
RewriteRule ^(.*)/?$ $1.html [L]
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
0

You may try these rules in your site root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/es/promo/ [NC]
RewriteRule ^(.*?)(?:\.html?|/?)$ /es/promo/$1.html [L,NC,R=301]
anubhava
  • 761,203
  • 64
  • 569
  • 643