I have a website thats live and another (for amends/approval) that is in a subdirectory called 'approval'. The idea being that once its approved I replace the live site. Is there a way to restrict access to this directory unless you have a direct link - maybe through .htaccess? Any other suggestions regarding protocol for this scenario? Thanks!
I've tried something with .htacces.
You can make a 403 error page. You can't go to a directory unless you have a link.
Make a .htacces file with the following code:
## Error Page
ErrorDocument 403 /403.html
Options -Indexes
the ## means that the line is hidden, for text
ErrorDocument 403 gives the place of the 403 error file. You can also type this: /errors/403.html
Options -Indexes blocks the directory's
I hope that it works for you
Related
I have seen some websites have their own File not found pages with their logos.
I want such a page for my website.
Please tell me how to make a such type of page that shows the user if the file is not found.
First of all you need an HTML or PHP file to show when the 404 is occurs. Let's do a simple HTML file like this:
<h2> 404 Not Found! </h2>
<pre> Seems like the resource you're looking for is not found </pre>
Let's call this file 404.html.
Now you have to configure your webserver to redirect the not found request to your new HTML document.
If you're using Apache:
You can do it in different ways, the most common and recommended would be using .htaccess file, which allows you to override Apache configuration of a virtual host. However, to be able to use the .htaccess file in your virtual hosts you need to add allowOverride all inside your apache configuration.
Example of apache config:
<Directory /path/to/your/project>
Options FollowSymLinks
AllowOverride All # This is the needed option
Order allow,deny
Allow from all
Require all granted
</Directory>
So now you're able to put a .htaccess file in your project, so just create it and put this inside:
ErrorDocument 404 /path/to/404.html/document
In case you're using Nginx:
You must add the error page inside the nginx configuration. Follow this guide in order to achieve it:
https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-to-use-custom-error-pages-on-ubuntu-14-04
if you are using Apache server
in your project folder
consider your project is in
/mySampleProject
create .htaccess file in /mySampleProject if you don't have one.
simply add this line in your .htaccess
ErrorDocument 404 /yourCustom404Template.html
I will suggest you, use a framework of whatever programming language you want to build this application. They have in-built custom arrangements for such requirement e.g.
if( file_not_found Logic ){
show 404_page
}
this is my first time with editing .htaccess, the situation is that I need to restrict access to a website for anyone except several IP-addresses and redirect others to a specific page. To do that I am using the following code in .htaccess:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !XXX.XXX.XXX.XXX
RewriteRule (.*) index.html [QSA,L]
The problem begins when I change the IP in this file - the background image which is used for the in index.html and stated in its internal css just stops appearing. I have tested this in Chrome and Firefox, in Firefox the background image reappears when the IP is changed to the one I have, in Chrome it doesn't reappear even after the IP changed back. I hope someone will be able to help me.
Best regards.
While rewriting is a powerful technique, it has many caveats and is relatively complex to get right. Here, the solution is not to use mod_rewrite at all. Apache's mod_authz_host module allows you to use the Require directive to specify which IP addresses are allowed to access resources.
If you need to display a specific page in case the Require is not satisfied, just specify an ErrorDocument for the error 403 (forbidden) which will be triggered.
If the error page then needs to access other resources, they need to bypass the IP restriction and be allowed using the Require directive:
Here is how your .htaccess file will look like:
Require ip XXX.XXX.XXX.XXX
ErrorDocument 403 /index.html
<Files "specific_image.png">
Require all granted
</Files>
Note that this causes an internal redirection in Apache.
If you want an external redirection and have the user have the actual index.html file in their browser's address bar, the configuration becomes a little bit more complicated because the file must be specifically allowed:
Require ip XXX.XXX.XXX.XXX
ErrorDocument 403 %{REQUEST_SCHEME}://%{HTTP_HOST}/index.html
<Files "index.html">
Require all granted
</Files>
<Files "specific_image.png">
Require all granted
</Files>
Note the use of variables to avoid hard-coding the absolute URL to the index.html file. Using a complete URL here is necessary to trigger the external redirection.
I have a domain domain.com
And when I type domain.com/something.html/new/one/square/new.html I am not getting a 404 error.
Where something.html is present in the account correctly.
Directory new is present in my document root.
Square is not present in my account.
By default, if part of the url points to a file, the rest of the url is treated as so-called "path info". In php you should be able to get this path info by checking $_SERVER['PATH_INFO']. If you don't want Apache to work like this, turn path info off in your main config file (httpd.conf) or in .htaccess in your root directory with the following directive.
AcceptPathInfo Off
For more information, please check the documentation for AcceptPathInfo.
Example: http://www.acuity-sports.com/skin/
I want this to be what they see below instead of my tree:
Forbidden
You don't have permission to access /skin on this server.
Take a look # how to prevent directory access and show forbidden error in php
Add a .htaccess file with
# disable directory browsing
Options -Indexes
There many ways to do so - a) apache vhost fole b) .htaccess
If u want follow (b), do following in .htaccess
Options -Indexes
Thanks
I am trying to Custom Error Pages using .htaccess. in this folder:/home/tamp/public_html/sandbox/test, I put .htaccess file, and inside i put this line:
ErrorDocument 404 /home/tamp/public_html/sandbox/test/error.html,
and then in frontend, I did a test, I open mysite/sandbox/test/te.php(te.php does not exist), but it still shows the default error page: The requested URL /test/tes.php was not found on this server. My error.html did not show up.
So what may go wrong here?
with ErrorDocument you can't use full file-system path:
URLs can begin with a slash (/) for local web-paths (relative to the
DocumentRoot), or be a full URL which the client can resolve.
so assuming that your website root folder is sandbox:
ErrorDocument 404 /test/error.html