3

I'm having some URLs (linked from outside) which do not have an extension, e.g

www.example.com/main

Originally there were files main.htm and main.html in the server's root.

However, an

RewriteRule ^main$ main.html [L,R=301]

does not work.

There is no folder main/ nor a file named main in the server root.

There are other entries in the .htaccess file which do work, so I'm sure the RewriteMod is active and working. I also have rewrite rules for typos (a link to www.example.com/xyz) that can be redirected.

RewriteRule ^xyz\)$ xyz/index.html [L,R=301]

The interesting thing is that the www.example.com/main URL appears unaltered in the browser (the URL in the browser bar doesn't change (as it does with a redirect)) but the page appears with the content of the file main.de.html. If I create a file named main.da.html it appears with that content (but only after an apache restart).

I can not figure out how it gets there or how to redirect it to main.html.

1 Answer 1

5

Disable MutliViews at the top of your .htaccess file:

Options -MultiViews

MultiViews (part of mod_negotiation) will ordinarily search for physical files that match main (in this case) as a basename (and would respond with an appropriate mime-type). This happens before mod_rewrite. So, if you had a file called main.de.html, this will be served as an internal subrequest (no redirect) before mod_rewrite has had a chance to process.

(but only after an apache restart).

This isn't something that would ordinarily require an Apache restart. Although it's possible that there is some caching going on. (?)

RewriteRule ^main$ main.html [L,R=301]

Aside: This is unlikely to be valid as an external redirect, unless you have an existing RewriteBase directive (I assume you must have)? Otherwise you should prefix the substitution with a slash. ie. /main.html (if the file is in the document root).

www.example.com/main URL appears unaltered in the browser

If MulitViews is not the problem, then it could be that the directive is in the wrong place in the config file and other directives are perhaps conflicting. We would need to see your .htaccess file.

1
  • Correct (yes, there is RewriteBase / futher up in the file. To make sure it's nothing conflicting, I had tried without the entire .htaccess file previously, but forgot to mention it). Dec 12, 2016 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .