I would like to know if it possible to set up a redirect in the htaccess file so that if an other website directly links to an image on my site, instead of the image opening in a browser window on its own, the page that the image is hosted on is displayed.
This page has the same name as the image i.e. if the image the other site is linking to is
www.mysite.com/imagename.jpg
then I want it to redirect to a page called
www.mysite.com/imagename/
Try this code :
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^www\.mysite\.com$
RewriteRule ^wp-content/main/[0-9]{4}_[0-9]{2}/([\.]+)\.(jpe?g|gif|png)$ /$1/ [R=301]
This might work.
RewriteRule ^(.*)\.(jpg|gif|png)$ /$1/ [R]
RewriteRule ^wp-content/main/.+/(.*)\.(jpg|gif|png)$ /$1/ [R]
Related
I want to display example: https://www.facebook.com in my members browser adress bar but display another site content in my webpage body..
I want use .htaccess file. Help me.
RewriteEngine on
RewriteCond %{HTTP_HOST} www.facebook.com$ [NC]
RewriteRule ^(.*)$ /page.php [R=301,L]
Not work.
I've built an AngularJS app and it contains views that could be considered different pages but the app is a single page app as in the page doesn't reload.
I've read up on using escaped fragment URLs to redirect search engines to snapshots of pages. My issue is when I try to share a page from my app on Facebook that it returns a 404, as can be seen using Facebook's open graph debug tool.
My app has a Larvel back-end feeding to an AngularJS front-end and my htaccess looks like this to redirect spiders and Facebook to the snapshots. As far as I knew this was working but I guess it's not.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/?(.*)$
RewriteRule ^(.*)$ /%1? [NC,PT]
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
My URLS are formatted to the user like: domain.com/#!/bike/id/bike+name
and the snapshot URLs are the same just without the hash bang i.e domain.com/bike/id/bike+name
I'm really stunmped on this one. Any suggestions or pointers would be greatly appreciated.
Facebook crawlers don't execute any Javascript so they won't see/have no idea about your Angular routes. What I've done in my project is I've mirrored the routes that need the open-graph tags in the back-end.
If my server gets a request for a page with og-tags it will make the necessary API calls to get the data, and attach them to the index template. If my initial request is the a page with no og-tags, I just render the regular SPA index. (I'm using HTML5 mode for urls so could be a bit different for you)
Also note that I said initial request to the server. This means that your og-tags won't change as you navigate within your SPA, they'll just be the tags of the first page you requested. This is actually a non-issue because Facebook makes individuals request to your server.
Let me know if this is unclear, I'll try to explain better.
I have a site built in codeigniter. We use short urls from our database & rewrite rules to redirect them to their full path.
For example,
RewriteRule ^secure-form$ form/contract/secure-form [L]
This works fine by itself. But I would like to use SSL on certain pages. I have edited the code so that if you go to one of these pages, all instances of http:// within the page are replaced with https:// but I need to rewrite the url to use it as well.
The pages all use the same template and all the content comes from the database so I can't just specify ssl on a particular directory.
The url's for the secure pages all start with 'secure' so I wrote the following rules and placed them above the other rewrites.
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/secure/?.*$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/secure/?.*$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^secure-form$ form/contract/secure-form [L]
RewriteRule ^secure-different-form$ form/contract/secure-different-form [L]
all other rewrite rules for specific pages follow
then the default rewrite further down...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
The problem is that when I add the rules to change the protocol, it ends up displaying 'form/contract/secure-form' in the url instead of 'secure-form'.
This renders the actual form on the page broken since it uses that url to build itself.
If I take out the rules that change the protocol, it displays secure-form in the url as it should, but the page is not secure.
What am I doing wrong?
----UPDATE----
Ooh, after over 20 hrs of searching, I think I finally have an answer. So, first time through, https is off & gets turned on. Then, because of the 301, it's run again & the page gets sent to form/contract/secure... But this time, https is on. Since the uri no longer STARTS with secure, it turns https off.
Hopefully, this will help someone else.
It is good that magneto offers watermarking of images so a watermarked image will appear as
http://www.yourwebsite.com/media/catalog/product/cache/1/image/de684549e4151748e56ee0dd7902c19f/m/y/my-first-image.jpg
This is good. But if anyone removes the cache/1/image/de684549e4151748e56ee0dd7902c19f part of URL so that it becomes
http://www.yourwebsite.com/media/catalog/product/m/y/my-first-image.jpg
He can view the image and copy it. What is best way to cope up with this problem?
This is how I managed to do it.
Put an .htaccess file in media/catalog/ folder in Magento with following code in it
Options +FollowSymLinks
RewriteEngine on
#Following line allows the actual images to be accessed by admin end directly
RewriteCond %{HTTP_REFERER} !^http://www.yourwebsite.com/.*$ [NC]
#Following line allows the watermarked images to be accessed directly. Rule says that if URL does not contain cache
RewriteCond %{REQUEST_URI} !(/cache/) [NC]
#This is the page where visitor will be redirected if tries to access images directly.
RewriteRule \.(gif|jpg)$ http://www.yourwebsite.com/do-not-try-to-steal-images.html/ [R,L]
Well, create yourself your images with the watermark !!! Like that if the cache is deleted, the cache will recreate an image from the already watermarked image
You can create an .htaccess file in the media/catalog folder with the following lines in it:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*?/cache.*)$ $1 [L]
RewriteRule ^(.*)$ $1 [F]
This will return a 403 to the user if they try to view the original file but let them see the images that are in the cache.
This breaks previewing the images in the admin as they display the original files and not a generated thumbnail.
Just as the title states. Say an individual accesses a file from my database, http://domain.com/database/file.zip. Once that file download has been initiated, I wish the browser to be redirected to the database directory again. Here's what I have so far:
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^Database(.zip)$ http://domain.com/db/index.html [R=301,L]
But, I get a 500 error.
And if I am being too picky, it would be nice to ignore this function on links such as: &file=something.zip.
Either way, getting the first portion to work would be fantastic.
Edit!
Here is what worked for me in the end. Cheers!
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} .*zip$|.*rar$|.*tar$|.*txt$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !domain\.com [NC]
RewriteRule ^(.*)$ /dl.php?url=%{REQUEST_FILENAME} [L]
Not really possible with mod_rewrite the way you have described: once the server has started delivering content (sent a 200 status code) there is no way to initiate a second response without a corresponding second request.
If you want to do this you'll have to do it on the client side: for example launch the download targetting a separate, hidden iframe and if the download starts then you can change the page location using window.location.