How long does it take for .htaccess changes to take effect? - apache

I have added url rewrite rules to my .htaccess file. Should I see these changes working right away?

Changes to .htaccess are immediate and do not require a restart. Normally, if you aren't seeing what you expect from .htaccess changes, you have a syntax error and should check Apache's logs for some idea of what's going on.

If you use redirect 301, clear browser cache.

NVM found it.
The .htaccess files follow the same syntax as the main configuration
files. Since .htaccess files are read on every request, changes made
in these files take immediate effect.

Apparently, some servers only check .htaccess files periodically. I've found this to be the case w/ our AWS host.
My source is only a comment below the answer here, but it matches my experiences and others seem to agree.

Related

Needs to ignore htaccess, when it contains wrong content

I will explain, what I want to do.
We have an eshop, which generates htaccess file (server is Unix). Sometimes, it crashes during generating htaccess file, then whole site (frontend, admin, cron scripts => everything) is returning server error 500, due to not finished content in htaccess file.
And here is my question. I created script, which will regenerate htaccess file. But this script cant be anywhere in root (or subdirectories), because it will also return 500. Also subdomains are in root in subdirectory /_sub.
Is there any change to put it somewhere, where our customer will be able to execute it himself?
I cant use another domain; so I am asking, if there is any chance to ignore htaccess file, when it contants wrong content?
Thanks a lot.
EDITED:
I know, maybe one solution is here, but I think it will consume much more time, to code it all, but maybe not:
on another domain code script, which will connect through socket to ftp of eshop domain
it will delete htaccess file and recreate it to basic content
executing that cron, which will regenerate whole htaccess file
This should work, I think.
The question is, how layman your customer are. Thw options: 1) you make this from cron 2) you put this in a cgi out.
But AFAIK the best were, if only a testing script from cron runs, and this reconstructed only the bad htaccess files.
I know, maybe one solution is here, but I think it will consume much more time, to code it all, but maybe not:
on another domain code script, which will connect through socket to ftp of eshop domain
it will delete htaccess file and recreate it to basic content
executing that cron, which will regenerate whole htaccess file
This should work, I think.

This web page has a redirect loop

Alright so I tried forcing either www. or allowing without the www. . It wasn't working so I took it all out of the .htaccess file and re-uploaded. Now when I try to view the website I get the error message of:
This web page has a redirect loop
How long does this take to refresh and not display this error message anymore? I tried clearing my cookies and flushing my DNS. It's still there.
Thank you!
Maybe have a look at this previous question's answers: How long does it take for .htaccess changes to take effect?
Changes to .htaccess should take effect immediately. It might help to re-check the obvious things (that the file on the server is indeed the correct .htaccess, etc)
Apache's help page on the matter: http://httpd.apache.org/docs/2.2/configuring.html#htaccess

mod_rewrite - Does Apache caches .htaccess rules? (still follow rules even after deleting the .htaccess file)

I was doing some tests with mod_rewrite in my wamp environment.
I tested a simple rule that I put at the root of one of my websites and asked it to redirect any request ending with index.php to localhost (there is no sense to it, just wanted to check the rule)
It worked, but after, any change I'd made to my .htaccess file rule was not reflected.
After a while I just decided to delete the .htaccess... well it's still doing redirection! I just don't understand it. Does Apache cache the rules or something (restarting services trough wamp menu didn't change anything)
(Don't ask for the exact rule I used, since I deleted the file, I don't think it's relevant anyway)
.htaccess files are processed each time a request comes through. It is possible that your browser cached the request being forwarded. Did you try it with httpfox or anything to see what the headers said?
Have you tried deleting the browser cache?

Popular techniques to debug .htaccess

I'm a self-taught coder and I like to debug by echoing suspicious variables and commenting out code.
Lately, I've had to learn more about the .htaccess file. I need it to do things like interpret php scripts as php5, url rewriting, limit file upload size etc.... I have a lot of trouble debugging a .htaccess file. I often have to migrate PHP applications from one shared hosting environment to another. Sometimes this breaks the .htaccess file (or instead, something in the .htaccess file breaks the site). I check to make sure domain names are updated.
Are there popular techniques for debugging a .htaccess file? Is it just look in the apache logs? Anything else?
Looking in the apache logs is the easiest way to debug .htaccess imho (adding rewriteLog Directive if necessary)
About migrating: if you are not using any physical file paths inside .htaccess (i.e. /var/www/site/script.php) they should be working without problems. If this is not the case, first try to remove all options and leave only redirect directives, in this mode you can see if it's problem with server configuration which denies rewriting of default settings.
Some reference

Updating Files on Apache

I'm having trouble with my Apache Web Server. I have a folder (htdocs\images) where I have a number of images already in place. I can browse them and see them on my web server (and access them via HTML). I added a new image in there today, and went to browse to it, and it can't be found. I double and triple checked the path and everything. I even restarted Apache and that didn't seem to help.
I'm really confused as to what's going on here. Anybody have any suggestions?
Thank you.
Edit I just turned on the ability for the images directory to be listed, browsed to it (http://127.0.0.1/images/) and I was able to see all the previous images that were in the folder, but not the new one.
Turn directory indexes on for htdocs\images, remove (or move out of the way) any index.* files, and point your browser at http://yoursite/images/
That should give you a full listing of files in that directory. If the file you're looking for isn't there, then Apache is looking at a different directory than you think it is. You'll have to search your httpd.conf for clues -- DocumentRoot, Alias, AliasMatch, Redirect, RedirectMatch, RewriteRule -- there are probably dozens of apache directives that could be causing the web server to get its documents from somewhere other than where you think it's looking.
make sure the caSE and spelling are 100% correct.
There is not magic in programming (some may disagree:), so look for silly errors. Wrong server? Case of your letters? Wrong extension?
There's a chance it could be due to the cookies stored on your device. I would delete all cookies to the website you're working on before you refresh again