F.P
F.P

Reputation: 17831

Rewrite rule to redirect html, but not any other files

I want my htaccess to redirect URL that end on ".html" to the index.php, but not any other files (so images can keep their href and still be displayed)

This is how my htaccess looks like now, it works for the HTML redirect, but styles or images are not displayed (because they are also redirected, I guess)

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^/?([\w./]+)\.html$ /index.php?object=$1 [L]
RewriteRule ^/?([^html]+)$ /$1

How can I get it to work, so only .html-files are redirected?

Upvotes: 0

Views: 319

Answers (2)

ase
ase

Reputation: 13489

RewriteRule ^/?([^html]+)$ /$1

Doesn't do what you want. It matches anything not containing any of the characters h, t, m or l. Your first rule is also strange; having both \w and . is redundant since . implies \w in addition to other characters.

Try this rule:

RewriteRule ^/?(.*)\.html$ /index.php?object=$1

Upvotes: 1

Capt Otis
Capt Otis

Reputation: 1260

RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php

Used this before worked great.

Upvotes: 1

Related Questions