Reputation: 91
I got redirects from /something to /something/ with that setting at my .htaccess file:
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301,QSA]
I want to add the same thing for pages which ends on 123.html
RewriteCond %{REQUEST_URI} [0-9]+\.html$
RewriteRule ^(.*[0-9]+\.html[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301,QSA]
It does't work... BUT!
RewriteCond %{REQUEST_URI} [0-9]+\.html$
RewriteRule ^(.*[0-9]+\.htm.*[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301,QSA]
That variant works perfect! Why apache does't like "l"? Who knows?
Apache version: 2.4.9
Upvotes: 1
Views: 34
Reputation: 785058
Your attempted not working rule is:
RewriteRule ^(.*[0-9]+\.html[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301,QSA]
Which doesn't work because your regex is incorrect as your Request URI is ending with .html
and there is nothing after .html
. Hence \.html[^/]
doesn't match the URI but \.htm.*[^/]
does match as last [^/]
matches letter l
.
Correct rule would be:
RewriteRule ^(.*[0-9]+\.html)$ http://%{HTTP_HOST}/$1/ [L,R=301]
PS: You also don't need to use RewriteCond
Upvotes: 1