Alexsander Akers
Alexsander Akers

Reputation: 16024

Redirect only HTML files?

Part One

I want to .htaccess redirect all HTML files to the home page. I looked at this guy's question (htaccess redirect all html files), and wrote this code:

RewriteCond %{HTTP_HOST} ^pandamonia.us$ [OR]  
RewriteCond %{HTTP_HOST} ^www.pandamonia.us$  
RewriteRule .*\.html$ "http\:\/\/pandamonia\.us\/" [L]

but the problem is that it also redirects the homepage to itself, causing the universe to end.

enter image description here

So my question, is how can I redirect every HTML page that is not the homepage to the homepage.

 

Part Two

Exclude certain subfolders and domains in redirects

Upvotes: 0

Views: 1737

Answers (1)

Rasmus Kaj
Rasmus Kaj

Reputation: 4360

Try changing .* to .+ in the regexp, that should mean 'at least one character' instead of zero or more characters, so the empty string should be avoided.

Wait. The initial '/' is included. Try it like:

RewriteRule /.+\.html$ "http\:\/\/pandamonia\.us\/" [L]

Upvotes: 4

Related Questions