Image files have got changed but pictures look the same - regex

I recently have got many files (especially image thumbnails) changed mysterily on my server. I am trying to figure out what happened.
I found a .htaccess file under my site's image folder, the image folder is in the same directory of my homepage. But I did not upload this file to the server, and did not do any configuration on cPanel that generating this file. The code is as follows:
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_USER_AGENT} (google|yahoo|msn|aol|bing) [OR]
RewriteCond %{HTTP_REFERER} (google|yahoo|msn|aol|bing)
RewriteRule ^.*$ index.php [L]
</IfModule>
Can anyone help to interpret what the above code does? Thanks in advance.
And also, when I synchronized my local site and the remote site in Dreamweaver, there were always some images especially thumbnails changed on the server, Dreamweaver prompted "No synchronization necessary", but if I viewed the log, Dreamweaver did say "this file has been changed since last synchronization" but marked with "ignored", when I compared these changed files with local site, winmerge prompted that "the two files are identical". I assumed Dreamweaver did not really find out the changes.
However, the image files changed found by my cron job "find /MY PATH TO DIRECTORY -type f -mtime -1 -exec ls -ls" did shows the difference when I compared them in winmerge (I could see the differences but could not understand those code of the image files". My question is how the image files get changed, the pictures look the same but the information containing inside the file get changed, how the change could be done and what the change could be for? Is there any security issues?
Any help would be appreciated.
Seahorse.

Related

htaccess match specific file types in root directory

I would like to match specific file types within the root directory the website. This htaccess file also sits in the root directly.
I've got this so far:
<FilesMatch "\.(php|png|ico)$">
Allow from all
</FilesMatch>
None of my attempts to restrict the matches to the same directory have been successful. I'm sure it's something super simple.
Try to do it this way:
<FilesMatch ".*\.(php|png|ico)$">
Allow from all
</FilesMatch>
I found out that only looks at the file name. It does not look at the directory part of the filename at all.
There is a but your not able to use it in a htacces file.
So the only way is through a Rewrite Rule. Something like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule "^(subdir/).*/.*\.(html|json)$" "-" [PT,L]
# -- Deny Everything Not Matched Above -- #
RewriteRule "/*" "-" [F]
</IfModlue>
The above will only allow html or json files to be accessed in a second (or greater) sub-directory within a directory called subdir in the same folder as the htaccess file. Everything else will be forbidden. Assuming mod_rewrite is installed. The files will also be treated as files, which is not the default behavior for a rewrite rule.

How do I make .htaccess such that going to the folder will show the contents of the folder?

How do I make .htaccess such that going to the folder in the web browser, where .htacess resides, will show the contents of the folder? Maye this is not something achieved by .htacess file but has something to do with changing the permission of the folder("directory").
I do not want to use an index.html file at all because the contents of the directory (folder) will change and then the index.html will be invalid.
I have a follow-up question. After this is done, is there then a way to programmatically use C# code to get the contents of the directory listing?
So you're trying to access your folders directory via the web browser:
All you need to add is:
<IfModule mod_autoindex.c>
IndexOptions FancyIndexing IconHeight=16 IconWidth=16
</ifModule>
You will get something that looks a bit like this:
You can of course play around with the settings and add extra things like:
NameWidth=25
DescriptionWidth=40
IconsAreLinks
This is not necessary though, it really depends if this is just for you, or public access too. Does it need to be pretty :P
You can add an .htaccess file inside that specific folder then add this at the top of the .htaccess file. Remove any index.html file that you have there also.
Options +Indexes

.htaccess rewrite where url basename is same as a directory name

I have a directory in my file structure named "finder" and I want to rewrite a url that has finder as the basename. For example take www.mysite.com/finder.
Here is the rewrite rule I'm trying:
RewriteRule ^finder/?$ /finder/directory/listings.php [NC,L]
Instead of succeeding with a rewrite i'm getting a 404 Page Not Found message. For what it's worth I have a rewrite rule that is taking this url www.mysite.com/finder/california with this rule...
RewriteRule ^finder/([a-zA-Z0-9+\-]*)/?$ /finder/directory/listings.php?s=$1 [NC,L]
.. and it's working.
I have tried DirectorySlash Off to my .htaccess but that's not working either. Any clues about what I'm missing? Thanks.
I see two potential troublesome areas:
The htaccess file with this rule cannot be in the finder folder. Make sure it is in the DOCUMENT_ROOT directory.
There could be an issue with the forward slash in the rewrite.
Tested on Apache 2.2 and 2.4:
RewriteRule ^finder/?$ directory/listings.php [NC,L]
URL in browser: http://www.example.com/finder
Redirected to: http://www.example.com/directory/listings.php
Let me know if this works.

mod_rewrite "No input file specified" error

Here is the situation: I have got ancient PHP scripts working fine on "old" server (Apache/2.2.3, PHP as module) and I need to move it to "new" server (Apache/2.2.16 (Debian), PHP as fcgi/suhoshin)...at least my ISP tells so.
I have got very simple .htaccess file that works fine on "old" server:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/css #Just an exception for domain.com/css dir
RewriteRule ^([^/]+)/?$ %{DOCUMENT_ROOT}/index.php/$1 [NE,L]
From what I studied mod_rewrite docs and site behaviour, when
domain.com/aaa/ opened, it rewrites/opens a script as if called domain.com/index.php/aaa/
domain.com/?a=1&b=2 opened, it rewrites/opens a script as if called domain.com/index.php/?a=1&b=2
etc., optinal slash at the end of the URL.
Other "301" redirects are made in PHP according to a database results/settings, that is not important now.
Now my problem is: When I transfer this .htaccess file + PHP scripts to the "new" server, I get this error message in browser:
No input file specified.
I have been trying several hours and studying regular expressions and Apache docs, but I cannot make it working. I guess there is something different in Apache2 configuration on both servers, but cannot find what that is. Have even tried to put echo at the beginning of the index.php to make sure this error does not come from PHP, but no :-( I am sure .htaccess support is on as I can generate errors when putting wrong directive. Not a regular_expressions guru. Can anybody help please?
UPDATE: Solved by changing it to:
RewriteRule ^([^/]+)/?$ %{DOCUMENT_ROOT}index.php [NE,L]
Insteresting that /$1 is not necessary, however I had to change PHP too to $_SERVER["REQUEST_URI"] from $_SERVER["PATH_INFO"].
Can you try this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/css [NC]
RewriteRule ^([^/]+)/?$ /index.php/$1 [NE,L]

Regex in RewriteRule, passing to bootstrap PHP file

I'm trying to figure out a solution for passing all relevant HTTP requests to my index.php bootstrap file.
The two rules I want to enforce are:
Any directory,
Any file with a .html or .ajax file extension (in any directory).
None of these files or directories actually exist - bootstrap PHP file will dynamically output relevant content.
Here is my current .htaccess file
RewriteEngine on
Options +FollowSymLinks
#RewriteCond %{REQUEST_URI}$1 !-f
RewriteRule ^/?(.+(?:\.html?)?)$ index.php [L]
RewriteRule \.ajax$ index.php [L]
The RewriteCond has been commented out as it didn't seem to have any effect, and with the correct RewriteRule it will be made obsolete anyway (image files, javascript files, etc. will not be matched by the rule so don't need to be checked for existance).
I think a regex expert could easily solve this, a plus would also be to combine the two rules into one regex.
Thanks!
This rule should do it:
RewriteRule .+\.(html|ajax)$ index.php