views:

21

answers:

1

I have two questions regarding RewriteRule, but they're both closely related so I hope it's OK I ask them both in a single post.

The first is that I'd like to strip trailing index.html's from the end of any URL, e.g.:

http://www.example.com/index.html -> http://www.example.com/

The second is to display the URL http://www.example.com/contact/ in the browser's address bar for all of the following URLs:

http://www.example.com/contact/
http://www.example.com/contact/index.html
http://www.example.com/contact/success.html
http://www.example.com/contact/failure.html

For example, if the user is redirected to http://www.example.com/contact/success.html I'd like that page to be displayed to them, but with http://www.example.com/contact/ as the URL. Is that possible?

+1  A: 

For the index:

RewriteRule ^(.*)/index.html /$1/ [R]

Second:

RewriteRule ^contact/(success|failure)\.html /contact/ [L]
Litso
Thanks; the first one is working but the success/failure one doesn't - it is redirecting all 4 URLs to `/contact/` while still showing the original URL. I'd like the opposite of that, i.e. show the `contact/success.html` page, but only show `/contact/` in the URL.
Rezzie
Ah, I misunderstood you then. I think that last bit is not possible though, if you rename the url to just /contact/, how will the website know if it has to show the success or failure page?
Litso
I was hoping it would serve up whether the form they'd just submitted succeeded or failed, whilst masking the URL so if they hit refresh they'll see the contact form again in case they want to resubmit.
Rezzie
There's ways to do that with php probably (check in the POST data if they succeeded and then show the proper page based on that) but not the way you want with .htaccess
Litso
Thanks for the pointers.
Rezzie