0

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?

2 Answers 2

1
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
1
RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php

Used this before worked great.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.