Need .htaccess snippet of code


#1

Hey all,

I’m reasonably familiar with HTML, and am just beginning to try some modifications to my .htaccess file.

Here’s what I’d like to accomplish:

Have all non-.html URLs rewritten to their *.html counterparts.

For example,

www.kirtancentral.com/testing

and

www.kirtancentral.com/Testing

and

www.kirtancentral.com/testing/

should all use rewrite to load www.kirtancentral.com/testing.html, the actual file.

Any thoughts?

Thanks!
~Daniel


#2

RewriteEngine On RewriteCond %{REQUEST_URI} ^/testing [NC] RewriteRule ^(testing)/? testing.html [L,NC]


#3

Thank you ~ yes, but is it possible to have this apply to all situations like this?

In other words, if the file name wasn’t “testing.html” but was anything at all? So I don’t have to type it in every time I create a new html page…

Thanks,
Daniel


#4

That wasn’t your original question, was it?

There are many answers to that question on the net if you take a minute to look. I thought you wanted help with your first question.


#5

Is that a fancy way of saying you’re not sure?

:wink:

That is my question actually, how to accomplish this for all names. Something like what you indicated, but with a variable instead of an actual word, and such that it doesn’t add “.html.html.html…” ad infinitum…

After hours of searching the net and trying things out without success, thought I’d post in here!

Thanks in advance for any helpful advice,
Daniel


#6

No it’s a fancy way of saying you changed the question…


#7

It’s a polite way of saying you should put in a little effort on Google yourself before you ask for help. I, for one, am willing to help others with specific issues because I can also learn, but it’s a waste of my time to repeat what can already be found on hundreds of websites if you take 30 seconds to look: https://www.google.com/search?q=hide+extension+htaccess


#8

[quote=“danielctucker, post:3, topic:56446”]
Thank you ~ yes, but is it possible to have this apply to all situations like this?[/quote]

Besides searching for solutions you can also study the reference documentation involved with doing this through .htaccess

See Apache mod_rewrite guide and in particular Apache Module mod_rewrite

RewriteEngine On RewriteCond %{REQUEST_URI} ^/testing [NC] RewriteRule ^(testing)/? testing.html [L,NC]

Two problems here, first the conditions should exclude requests for existing files and directories - that should also eliminate recursion. Second of course you would then want to use backreferences so the url-path doesn’t have to be hardcoded. Don’t forget to consider for matching to the end of the url-path as well as the beginning, ie maybe you want to match /testing but not /testing/test


#9

agreed on both accounts, but based on the initial question, it sounded like s/he a) didn’t have any files or directories named [font=Courier]testing[/font] and b) wanted a solution that would be case insensitive. I’m not sure of a way to get [font=Courier]testing[/font], [font=Courier]Testing[/font], [font=Courier]testing/[/font], [font=Courier]TESTING[/font], and [font=Courier]tESTING[/font] to all point to [font=Courier]testing.html[/font] without a rather ugly looking RE or using a script to change the request to lower case.