0

I've changed my web hosting provider and now I have a configuration problem: In the root of my site, I have a file called beta.html. The Apache configuration on previous webhost would serve its content even if accessed as http://example.com/beta or http://example.com/beta/. The Apache on the new webhost treats those two cases as 404 error. Note that there is no directory named beta on that site.

Is there something I can do with .htaccess so that it serves the contents of beta.html without a client side redirect?

3 Answers 3

1

Enable MultiViews for the Directory in question.

<Directory /my/web/site>
    Options MultiViews # and your other options
</Directory>
1
  • Confirmed with previous hosting provider, this is what they had enabled.
    – Palimondo
    Jan 23, 2014 at 8:25
0

My first guess is that your old hosting provider had Aapche's mod_speling enabled, which allows Apache to correct minor case mismatches and/or spelling errors before displaying a 404 error.

Best practice is to leave it off, because it can cause quite a bit of overhead and doesn't discourage bad webdesign.

2
  • OK, is there something I can do? mod_rewrite?
    – Palimondo
    Jan 17, 2014 at 15:07
  • You could try to enable mod_speling in your config, it's directives are even alllowed in .htaccess files.
    – HBruijn
    Jan 17, 2014 at 15:17
0

You can use mod_rewrite to do this. There are numerous tutorials on the web.

However I would caution that this is not a recommended practice due to conflicts, complexities, and SEO reasons.

For example see: Rewrite .html file extensions with htaccess I've not tested this but have seen people use this and similar approaches.

Note that this will impact your entire site. If you just want to do one URL, then add a RewriteCond so the filtering only applies to that URI.

# This tag ensures the rewrite module is loaded
<IfModule mod_rewrite.c>
  # enable the rewrite engine
  RewriteEngine On
  # Set your root directory
  RewriteBase /

  # remove the .html extension
  RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
  RewriteRule (.*)\.html$ $1 [R=301]

  # remove index and reference the directory
  RewriteRule (.*)/index$ $1/ [R=301]

  # remove trailing slash if not a directory
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} /$
  RewriteRule (.*)/ $1 [R=301]

  # forward request to html file, **but don't redirect (bot friendly)**
  RewriteCond %{REQUEST_FILENAME}.html -f
  RewriteCond %{REQUEST_URI} !/$
  RewriteRule (.*) $1\.html [L]
</IfModule>

You must log in to answer this question.

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