https before address shows only files in private_html folder on host - ssl

when i try my webpage address with https, page shows only files in the private_html folder not public_html.
but my website runs in the public_html. for example i use an index.html file (including forwarder script) and when you type https://alirezah.net it redirects to http://alirezah.net.
how can i fix it? I wanna use cloudflare ssl service but this happens.
I tried to edit htaccess but it doesn't help

If your website is hosted on Directadmin, then follow these steps:
Log in to your DirectAdmin control panel
Click on Domain Setup
Click on the domain name you wish to change this for
Choose the Use a symbolic link from private_html to public_html - allows for same data in http and https checkbox.
Note the warning message - anything in private_html will be removed, so be sure you do not have content left here that you want to keep.
Accept the warning notice and your now pointing you are private_html directory to the public_html directory.

If your website is installed in private_html it will be deleted using this function. If you want to keep your website installed in private html and also redirect http to https, then you need to create a .htaccess file in public_html with the following contents:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://example.com/%{REQUEST_URI} [R,L]

Related

Can i block websites with %{HTTP_HOST} and RewriteCond?

Im trying block websites in certain hours, but i cant use correctly the rewrite cond or what is the better way?
<IfModule rewrite_module>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.facebook.com$ [NC]
RewriteCond %{TIME_HOUR} ^(11|12|13|14|15)$
RewriteRule .? /restrinction_social.html [L]
</IfModule>
are you trying to block the website so you can internal network can not access it?
the .htaccess is for domains hosted on your server your configuration could work if your server is the host of facebook.com
if you are trying to block your internal network to access facebook.com maybe you can do it with DNS or a PROXY server like squid
You may try this procedure on how to block website on your network through httpd.conf.
Navigate to your Apache installation directory, which is typically the /etc/httpd/conf directory on most servers. The path to the installation directory is case-sensitive.
Locate the httpd.conf file in the conf directory, and then open using vi command or your text editor. You can use cp command to create a backup. Please see the sample below:
$ cp -R httpd.conf httpd.conf.bak
Scroll down to the "ProxyBlock" line.
Enter the domains you want to block in the "ProxyBlock" line. Add the domain name to block after the last domain name. You do not need to add a comma -- just add a single space after the last blocked domain name. Please see the sample below:
Proxy Block google.com facebook.com
Save the file to the server, making sure to preserve the file's case-sensitive name. Test that the file is working properly by trying to visit the blocked websites using a computer located on your network.
Hope this information works for you.

Redirect a forbidden URL in Apache

I would like to move an entire directory and its subdirectories from one Apache server A to another Apache server B, and then create a redirection from A to B.
i.e.
http://server_a.com/docroot/dir to http://server_b.com/docroot/dir.
This is what I did:
I copied the files and directory structure under dir from A to B
I deleted the directory dir on A
I created a rule in docroot/.htaccess on server A that reads
Redirect permanent dir/ http://server_b.com/docroot/dir/
But when I go to http://server_a.com/docroot/dir/path/to/file/index.html, I get a 403 Forbidden, even if the target page http://server_b.com/docroot/dir/path/to/file/index.html is up.
I know that the .htaccess is read by Apache, because it correctly controls other parts of server_a. I am not root on these servers. I have also tried with a RewriteRule, with the exact same results.
How should I go about creating a redirect in this case? Thanks.
If you have mod_rewrite enabled than you can do this
RewriteEngine On
RewriteRule ^/?docroot/dir(/.*)?$ http://server_b.com/docroot/dir$1 [R=301,L]
Put it in your .htaccess file in the Document Root directory http://server_a.com/.
Note:
Delete you Browser cache first.
You'll need the leading / in the old URL. Like this:
Redirect permanent "/dir" "http://server_b.com/docroot/dir/"
See the mod_alias docs for more details.

apache blocking content from viewing users by hitting url directly

I have disabled the browsing of content by using
Options -Indexes
Now I want to disable directly access of assets(images and videos) by hitting url directly for any project that is present in htdocs folder.
My webserver is Apache Tomcat.
I am accessing the content from a project in apache using a url.
The URL should serve the content in JSP/HTML files deployed in Apache Tomcat. But should be blocked if hacker finds the URL from page source and put the URL in browser.
Thanks in advance.
you have two solutions
1) create a .htacess file and set rules
2) store your protected file somewhere outside the web root folder and acess them using php or any other language.
2nd one is recommended. you can only access your files through server side codes(php,...). Crete a file handling script and check permissions when accessing.
To go with .htaccess file you need to have something like..
Try following:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
Returns 403 if you access image directly, but allows them to be displayed on site.
Change localhost to the server/domain name of yours.
NOTE: it is possible that when you open some page with image and than copy that image's path into the address bar you can see that image, it is only because of the browser's cache, in fact that image has not been loaded from the server

htaccess redirect URI to parent directory

I have a website hosted in /var/www/thesite (apache server), it's a Symfony2 website so inside this folder I have a web folder to which my virtual host is pointing.
So my virtualhost is www.mysite.com -> /var/www/thesite/web
In this web folder I have a .htaccess to format URL nicely.
Now, I've added an API in /var/www/thesite/api, the API is implemented using Silex.
I want to redirect all request http://www.mysite.com/api to this new framework.
So I've added in /var/www/thesite/web/.htaccess
RewriteCond %{REQUEST_URI} ^/api
RewriteRule ^api(.*)$ ../api/web/index.php [NC,QSA,L]
But I get:
Bad Request
Your browser sent a request that this server could not understand.
I'm not sure if I can access parent folder in the .htaccess. I don't want to change my virtualhost target directory to avoid security breach.
How can I solve this issue?
You can't route a request to outside of the site's document root, which is /var/www/thesite/web. So you can't access /var/www/thesite/ or /var/www/thesite/api from inside the /var/www/thesite/web directory. The 400 Bad request is because of the ../api/ bit of your rule's target.
Something you can try doing is just using php to include/require the api's index.php:
RewriteRule ^api/(.*)$ /index_api.php [L]
And in the index_api.php you can include or require the "../api/web/index.php" file.

read images from root directory in subdomain with htaccess

I have a domain like example.com where root directory is web.
I have created a subdomain happy.example.com where directory is outside web folder called happy and connected it to happy.example.com.
My webpage tree looks like
happy
web/images
So all my images for root directory are stored in (web/images)
example.com/images
So a full path to an image can be
example.com/images/me.png
Now i have created a sudbdomain which i call:
happy.example.com
What i would like to do is if i type
happy.example.com/images/me.png
then i should be able to see the picture.
So somehow i need to link all images folder to a subdomain from root directory in web.
I hope you guys got my question.
I guess i shoud have an htaccess file with all funny stuff in happy folder?
Cheerz
Since the two document roots of your two domains aren't connect to each other (one inside the other, or the same), you'll need to either redirect or proxy, or, use a script.
To redirect is easiest, but it'll change the URL in the browser's location bar:
Redirect 301 /images http://example.com/images
or using mod_rewrite:
RewriteEngine On
RewriteRule ^images/(.*)$ http://example.com/images/$1 [L,R=301]
To proxy, you need to have mod_proxy loaded, which isn't always the case if you're using a webhost or hosting service. But you can use the P flag in mod_rewrite to do this:
RewriteEngine On
RewriteRule ^images/(.*)$ http://example.com/images/$1 [L,P]
The last option is to route all image request to a script, like a php script or something. And the script itself returns the image:
RewriteEngine On
RewriteRule ^images/(.*)$ /load_image.php?image=$1 [L]
then you'd have something like:
<?php
header("Content-type: image/jpeg");
readfile('../web/images/' . $_GET['image']);
?>
Obviously, you'd need to check the extension and return the correct content type depending on the image type.