Cannot get .htaccess file to work inside of htdocs directory

I have placed a new .htaccess file in my htdocs directory. I’m primarily interested in setting “Cache-Control: no-cache”. However, it is now clear to me that this is not working. I have gone so far as to inject lines into .htaccess to purposely break it in order to see if it is being read or not. It is very clear that .htaccess is not being read.

What else do I need to do to force this file to be read? I serve of the web claims that .htaccess not being read is usually due to the AllowOverride setting in your site configuration. (.htaccess not being read - Stack Overflow) However, I do not see any place where I can alter this setting. Does anyone know where I need to go in order to do so? Thank you.

“A search of the web” is what I meant to say

That sounds like a HTML meta thing and not an .htaccess thing.

You can use this guide:

Why don’t you create a 301 redirect?

Create a rule in the .htaccess to redirect the request made from the root of your domain to Google:
Redirect 301 /

If Google opens when you access your domain in a brower, it’s working.

Thanks Greenreader9 … oddly, I was originally going to go that route. However, most of what I read on the web told me to use .htaccess instead. Do you (or anyone else reading this) know how well the meta tags work? I guess I’ll have to try them and find out!

Thank you alexvf! Google does indeed open in my browser, so I guess .htaccess must be working after all!

Yep! .htaccess is better!

The meta redirect tag dosen’t work as well as .htaccess, so .htaccess is better.

Yep! Just change to what ever you want it to be!

AFAIK the Header option is disabled in .htaccess. You can do it via PHP using the header() function (see code below)

header("Content-Type: application/json");
header("Expires: on, 01 Jan 1970 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

The AllowOveride option (from what I can remember) can only be altered in the Apache httpd.conf which is located at the root of the server.

Your best option is to use the PHP code above (place it at the top of your PHP file)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.