Redirect http url to https

Force redirect http to https using htaccess

Force redirect http traffic to https

Redirect http to https url using simple file. If you have recently switched to https version, which is recommended, then you want to force the traffic to https.

This can be accomplished using .htaccess file.

How to redirect https to http

1. Create/update the .htaccess file on your root website.
2. Add the following line on the top part of the .htaccess file


RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

3. That is it. You don’t need to restart the server for this case.

You can refer this page for more htaccess examples

You don’t have permission to access / on this server. Apache error

Apache refusing to serve with you don’t have permission to access error

Here are things to fix the problem

Have your config in your apache config like this:


       ServerName someWebname.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        
                Options All
                AllowOverride All
                require all granted
        

1. Make sure the directory you are accessing has at least 755 permission mode
2. Make sure to restart the server after you change the configs
3. Check if you have .htaccess file with different setting
4. In some cases, make sure the directory is accessible by apache – www-data.

Redirect to home page on 404 – htaccess

How to redirect to home page on page not found 404

If you have a page that is not found, then google and others will penalize your site for not finding the page. Hence, you should handle that internally.

At least the easiest thing one can do is to redirect the site to the home page using .htaccess directives.

Homepage redirection 404

First create a .htaccess file if you don’t have one yet. Place this .htaccess file in the root of the website.

Then add the following line in the .htaccess file.


Options -MultiViews
RewriteBase /
RewriteEngine On
#if you have other redirect rules, have them here
#put this at the end of the file.
ErrorDocument 404 /

Mind you, the page you are going to redirect to should be relative path.
On the above file, those starting with # are comments and won’t be read by the server.

Hope it helps. Let me know if this helps you or if you have better method by leaving the comment down.

airplane in he runway

Deploying Symfony on Production Server

Time to ship your symfony app to production? Here are some flight checks. Lets assume your symfony app is in folder symfony-app

1. Don’t put Symfony app in the public accessible folder on your server

If your servers public facing folder is, say, /var/www/html, then don’t put the whole symfony folder there.

Choose another deeper and non-public facing folder. Let say /apps/symfony-app. I will list how you would put the public facing folders later.
For this to happen run this command on your server

mkdir /apps

2. Pushing your code to production server

You can use FTP client like filezilla or cyberduck and put your code in /apps
If you are using git, then you can clone your app like this

cd /apps
git clone https://username@bitbucket.org/username/symfony-app.git symfony-app

Continue reading Deploying Symfony on Production Server

Apache listing directory – I swear I have index file!

OK, the ultimate wisdom is you will put your index file on the webserver accessible directory and your website would be visible – right? Well, not all the time.
Apache might decide to list your files even though you put your index.php in the directory you are expecting..
The thing lies on the default configuration of your server. If the default http.conf file has the directory setting to list then it will list even in the virtual hosts.
The fix Add your DirectoryIndex

So typical .htaccess or your setting in http.conf file would look like

...you other configs
   DirectoryIndex index.php //or whatever you want it to start from 
....your other configs

vOILa