I have site with Joomla on my local intranet. and I'm add code on .htaccess
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://localhost:8081/.*$ [NC]
RewriteRule ^.* /403-page [L,R]
If I'm test with type address directlink on addressbar successfully redirect, and can't open anything for directlink, and url direct to :
http://localhost:8081/403-page
the problem is, if I want open with type http://localhost:8081/intranet for main page of intranet I cant open this, it will test with me unscript code then put again script for open the main page, and success to open main page, then i put again script for script only use. everything is OK with I want. open anything link from website, and cant open directlink with type link on addressbar.
##Options -Indexes
##RewriteEngine On
##RewriteCond %{HTTP_REFERER} !^http://localhost:8081/.*$ [NC]
##RewriteRule ^.* /403-page [L,R]
how to tricks and tips for this, I can open mainpage intranet only with type on addressbar:
http://localhost:8081/intranet/
and anything type directlink set cant to open...???
Add a condition to exclude requests for /intranet/:
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/intranet/?$
RewriteCond %{HTTP_REFERER} !^http://localhost:8081/.*$ [NC]
RewriteRule ^.* /403-page [L,R]
Related
Lots of info nearly solves this, but nothing will quite crack it yet.
The site has a front-end (all in root basically), and an admin panel living in /admin. Basic stuff.
The site runs remotely on http://www.example.com and locally on http://foo
I want nothing locally redirected at all.
On the live server I just want front-end traffic redirected to a sub-folder /coming_soon but no redirection on the admin panel. So the client can start work in admin, but the public will only ever see the content in /coming_soon. (Plus I guess the admin login page, but that's fine).
Closest I came was:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !=foo
RewriteRule ^$ /coming_soon [L]
</IfModule>
But that let me hit the "real" front-end by browsing directly to http://www.example.com/index.php
Your help much appreciated.
Hopefully I got your question right^^ Wasn't sure about the /admin part, who should access or if possible no one or...But the following is my take on your problem:
RewriteEngine On
#excludes HOST=foo and URI=/admin from rewrite to /coming_soon
RewriteCond %{HTTP_HOST} !^foo [OR]
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule ^ http://www.example.com/coming_soon [R=301,L]
You can additionally set a location-directive and only allow entering /admin from specific IP(s).
<location /admin>
required ip 10.11.12.13
required ip 20.30.40.0/24
</location>
update
RewriteCond %{HTTP_HOST} !=foo
RewriteCond %{REQUEST_URI} !/(coming_soon|admin)
RewriteRule ^(.*)$ /coming_soon [R=302,L]
And R=302 is just temporary rewrite = won't be cached by browsers with target location. R=301 would tell browsers to save the target /coming_soon right away.
...if any one can improve this, or make it more elegant, I'd love to hear!
RewriteCond %{HTTP_HOST} !=foo
RewriteCond %{REQUEST_URI} !/coming_soon
RewriteCond %{REQUEST_URI} !/admin
RewriteRule ^(.*)$ /coming_soon [R=302,R]
I have a PHP website that I own. I want to temporarily disable the website while I am making my changes (there are a lot to do). I tried to rename the index.php file but the end-user can always navigate to a page by typing the URL ( or if he had bookmarked the page ). Is there a way I can disable the whole website temporarily?
Edit : This accepted answers work for an apache web server. What I am using presently is IIS6 ( and not IIS7 where the same rewrite can be done in web.config file ). Is there a way around for this problem in IIS6?
You can use .htaccess file to redirect to maintenance page:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]
Some useful links:
http://www.shellhacks.com/en/Redirect-Site-to-Maintenance-Page-using-Apache-and-HTAccess
http://perishablepress.com/htaccess-redirect-maintenance-page-site-updates/
http://wp-mix.com/maintenance-mode-htaccess/
While bartek beat me to an Apache mod_rewrite rule that would force the site to redirect all traffic to a maintenance/offline page, I wanted to post my variation on the idea which can allow a specific IP address to access the site:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123.45.67.890$
RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
RewriteCond %{REMOTE_ADDR} !^::1$
RewriteCond %{REQUEST_URI} !^/offline.html$
RewriteRule ^(.*)$ http://your.great.website/offline.html [R=302,L]
Just a note that depending on your version of Apache, you might have to escape the . and : in the IP addresses like this:
RewriteCond %{REMOTE_ADDR} !^123\.45\.67\.890$
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
RewriteCond %{REMOTE_ADDR} !^\:\:1$
The idea is if the visitor is not coming from the IP address 123.45.67.890—or the localhost addresses of 127.0.0.1 (IPv4) or ::1 (IPv6)—and the URI requested is not /offline.html then redirect that person to http://your.great.website/offline.html.
Which means you should just replace 123.45.67.890 with the IP address you would be connecting from to allow you to have a window into the website while you perform work. But anyone else who is not 123.45.67.890? Well, they see the offline.html page.
I would also propose this solution.
RewriteEngine On
RewriteCond %{QUERY_STRING} !access=dbcaf771cc0c4e23a0fc895d0afa106f
RewriteCond %{REQUEST_URI} !^/maintenance.html$
RewriteRule ^(.*)$ /maintenance.html [R=302,L]
The idea is unless your request contains access=dbcaf771cc0c4e23a0fc895d0afa106f within the query string, you'll simply get redirected to the maintenance page.
hello all i am working on a site where i dont want any user to browse my site directory or to view any image/file inside the directory by just typing the address of the image or file in address bar or by any software help.
i think this is possible my .htaccess rewrite rule
can anyone help me please
my site directory names are members,images,ads
from some where on this site i found this
RewriteCond %{REQUEST_URI} ^/news/latestnews/(.*)$
RewriteCond %$1 ^(.*)2012(.*)$
RewriteRule ^(.*)$ /news/2012 [R=301,L]
which redirects the user to new directory but i dont know how to work with htaccess i can not modify the code
You can add following to top of the htaccess file you already have
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?YOURDOMAINNAME.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.YOURDOMAINNAME.com [L]
Options -Indexes will restrict directory listing
RewriteCond %{HTTP_REFERER} !^http://(www\.)?YOURDOMAINNAME.*$ [NC] checks if the request to a file is from within script or if the request has a referrer from your domain
RewriteRule \.(gif|jpg|png)$ http://www.YOURDOMAINNAME.com [L] will redirect to your home page, if some one tries to access the file directly. You can added file extension to this rule by separating it by pipe | symbol, e.g. gif|jpg|png|doc|pdf
We only want users from a specific website to use our services. Is there a way to redirect all traffic that does not come from a specific referrer, to a website of our choosing, via htaccess?
Also, this is for the first page only. So if they get to our site, they're going to browse a new page, and their referrer for the new page would apparently be the site they are already on.
Thank you!
Try adding this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://the-ok-domain.com [NC]
RewriteRule ^/?first-page.html$ http://the-website-of-your-choosing.com/ [L,R]
You could also make it so you add your own domain to the referer check:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://the-ok-domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http://your-domain.com [NC]
RewriteRule ^ http://the-website-of-your-choosing.com/ [L,R]
Then you can include all of your pages in the check.
Note that referers can be easily forged and any htaccess file using mod_rewrite in any of your subdirectories will supercede these rules (unless those htaccess files have the RewriteOptions inheret option set)
Didn't work for me, I've made this small change to redirect traffic from google:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^(.*)\.google\.(.*) [NC]
RewriteRule ^(.*)$ https://www.my-site.it/$1 [L,R]
Is there a .htaccess script I can use to redirect the url of an image to an actual web page?
What can I do to make it so when someone accesses an image via their address bar by typing in: http://www.sitename.com/uploads/192-file-name-here.jpg
or other extensions like
http://www.sitename.com/uploads/235-file-name-here.png
It will instead redirect the user to the web page:
http://www.sitename.com/view/192-file-name-here/
I want to still be able to place the images in image tags across the site and on external sites though.
RewriteCond %{HTTP_REFERER} !^https?:\\www\.sitename\.com
RewriteCond %{REQUEST_URI} (.*)\.jpg$
RewriteRule images/(\d+)\.jpg http://www.sitename.com/view/$1.html [L,R=301]
RewriteCond %{HTTP_REFERER} ^$
Can this be modified/re-written to perform my function?
put this in your .htaccess, it will redirect all requests that are sent directly by user.Note: Other sites,as you mentioned can put your images in their pages.
RewriteCond %{REQUEST_URI} ^/uploads/(\d+)-(.+)\.(png|gif|jpe?g|bmp)$ [NC]
RewriteCond %{HTTP_REFERER} ^$
RewriteRule (.*) http://www.sitename.com/view/%1-%2/
Yes you can always redirect images to a webpage or anything using .htaccess.
But images/(\d+).*\.jpg may be better.