ISAPI Rewrite Syntax To Stop Image Hotlinking - windows-server-2008

I have followed a couple of tutorials for adding rules in ISAPI to stop image hotlinking for a website I own.
I have added this
RewriteCond Referer: (?!http://(?:www\.mydomain\.co\.uk)).+
RewriteRule .*\.(?:gif|jpg|png) /images/block.gif [I,O]
BUT all the images are changed on the actual site to block.gif? No matter what I try it just replaces all the images and not just changing the image for people hotlinking? Any ideas what is wrong with my syntax?

First, please specify the version of ISAPI_Rewrite you are using - is it 2 or 3?
Then could you please specify more explicitly what was it you tried: "No matter what I try..."
And finally, try to fix the cond like this:
RewriteCond Referer: (?!.*mydomain\.co\.uk).+

Related

How can i rewrite a image file name to query string via rewrite rules in Apache

I am trying to create a php script that will check if a image is local and if not retrieve it from remote site. I want the user to call the image like this.
http://media.myimage.org/media/2AF97A30-42F7-4E08-8BF6-020316D6F161.jpg
To make it work i need to create a rule that will rewrite the url to the following request
http://media.myimage.org/media/image.php?id=2AF97A30-42F7-4E08-8BF6-020316D6F161
i tried multiple ways and tested them via https://htaccess.madewithlove.be/ but they all fail with
rule was not meet
i want to take my regexpr '/([{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?)(.jpg)/m'
and if it is meet then translate it to 'image.php?id=${1}' if not i want to redirect to a 404 page not found
With some more research I was able to solve my issue. Not sure its the best way but it works. If anyone has a recommendation to improve I am all ears.
RewriteEngine On
RewriteBase /
RewriteRule ^/?([{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?+).(jpg|png|gif)$ /madia/image.php?id=$1&format=$3 [L]
RewriteRule (.*) /images/404.php?image=$1 [L]
The above will accept any image request as long as the image name is a valid guid and the file has the extension of jpg or png or gif. If this Rewrite rule is hit we will exit, if not we will do the 404 rewrite.

confused with Mod rewrite RewriteRule

everything at my website is served from a master index.php at Document root
so normally all the functions looks like ./index.php?storage=seven
i wanted to make it looks better, so tried to use Mod_Rewrite as shown below
RewriteEngine On
RewriteRule ^/storage /index.php?storage=seven [L]
Now i am able to access the function using ./storage
but when somebody types ./storage/ (an extra '/' at end) or ./storage/some/junk the Link still works but the path to images/css/script in my page brakes(the paths to these is broken), which means, i just need it to be working for ./storage and everything else should give 404 error (./storage/ and ./storage//... to give 40)
Please help me out here, i am very new to Mod_reWrite
Thanks
Small change in rule ... and it started working
RewriteRule ^storage$ index.php?storage=seven [L]
By the way seven here is hard-coded from the Rule itself, please don't get confused with that
Thanks

Rewrite a URL Apache

I’m attempting to rewrite a link on my Apache config file so that it looks like an internal link, but is actually external.
The link on my site will look like this, and have multiple querystrings.
http://www.mysite.com/myscript.asp?somevar=1&othervar=2
But when clicked will be rewritten as this:
http://www.othersite.com/script.asp?somevar=1&othervar=2
Here is where I am so far (not working):
RewriteRule ^myscript.asp?(.*)$ http://www.othersite.com/script.asp?(.*) [L]
Can anybody get this rule working? Thanks!
I hope this would be helpful:
RewriteRule ^myscript\.asp\?(.*)$ http://www.othersite.com/script.asp?$1 [L]
Note: question mark(?) and dot(.) have special meaning in reqular expresion, so if you want to use them as meaningless character put \ before them!

How do I rewrite www.sitename.com/thing/thing.php?otherthing=something-like-this to www.sitename.com/something-like-this?

How do I rewrite
www.sitename.com/thing/thing.php?otherthing=something-like-this
to
www.sitename.com/something-like-this?
please help me with this as I can't seem to succeed. My host uses apache 2.2. Many thanks for your help!
Update
No I don't need that trailing ? However, I used the Rewrite rule you offered me and it still ain't working. I also added a RewriteEngine On before the rules.
I have Linux hosting, .htaccess and the code is obviously semantically correct, cause otherwise I would get the all so popular 500 internal server error. I placed the .htaccess file in the folder thing and in the root of the site, but it still won't work.
There should be an option to display it in directory format instead of the PHP ? format. If not, you could use the .htaccess mod_rewrite rule to make that display in the /folder/ way.
The way I do it is that I just upload my files and each page name is index.html and then I create folders, and put each index.html in the folder. Like this:
/guidelines/
In that folder is index.html, so instead of it being /guidelines.html it's /guidelines/
Looks better without .html
You need to use mod_rewrite:
RewriteCond %{QUERY_STRING} ^otherthing=(.*)$
RewriteRule ^thing/thing.php$ /%1? [L]
No idea if you meant to have that trailing ? at the end of the rewrite, I don't think that's possible. Note that the ? at the end of the RewriteRule is to get rid of the query string, otherwise, the rewritten URL will still have the ?otherthing=something-like-this at the end.

mod_rewrite to alias one file suffix type to another

I hope I can explain this clearly enough, but if not let me know and I'll try to clarify.
I'm currently developing a site using ColdFusion and have a mod_rewrite rule in place to make it look like the site is using PHP. Any requests for index.php get processed by index.cfm (the rule maps *.php to *.cfm).
This works great - so far, so good. The problem is that I want to return a 404 status code if index.cfm (or any ColdFusion page) is requested directly.
If I try to block access to *.cfm files using mod_rewrite it also returns a 404 for requests to *.php.
I figure I might have to change my Apache config rather than use .htaccess
You can use the S flag to skip the 404 rule, like this:
RewriteEngine on
# Do not separate these two rules so long as the first has S=1
RewriteRule (.*)\.php$ $1.cfm [S=1]
RewriteRule \.cfm$ - [R=404]
If you are also using the Alias option then you should also add the PT flag. See the mod_rewrite documentation for details.
Post the rules you already have as a starting point so people don't have to recreate it to help you.
I would suggest testing [L] on the rule that maps .php to .cfm files as the first thing to try.
You have to use two distinct groups of rewrite rules, one for .php, the other for .chm and make them mutually exclusives with RewriteCond %{REQUEST_FILENAME}. And make use of the flag [L] as suggested by jj33.
You can keep your rules in .htaccess.