0

I'm not very experienced with .htaccess related stuff, I was looking to get some help. Basically what I'm trying to do is this:

Any request that looks like this (example):

/foo.html

Would be rewrote to:

/foo

And any request that is a static file, I'd like it serve:

/index.html

Does that make sense? Any idea how to do this?

Example

Here's what I have so far, though it's not correct as far as I know:

RewriteRule %{REQUEST_FILENAME} !-d
RewriteRule %{REQUEST_FILENAME} -f
RewriteCond ^(.*)$ $1.html [NC,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
3
  • I didn't get your 2nd requirement. What do you mean by any request that it's a static file Commented May 15, 2015 at 12:46
  • @anubhava sorry, I mean is. Commented May 15, 2015 at 12:51
  • Your comment got truncated. Better you edit question to clarify with examples. Commented May 15, 2015 at 12:54

1 Answer 1

1

Check for existence of .html file before adding it to URIs:

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{REQUEST_FILENAME}.html -f [NC]
RewriteRule ^(.*)$ $1.html [L]

RewriteRule . /index.html [L]
Sign up to request clarification or add additional context in comments.

3 Comments

Hmm, I got a 500 Internal Server Error using this.
It happens with any URL I try.
I found a typo mistake in my code. Fixed it now, retry now.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.