Help redirecting to https on Apache

asked 2018-11-28 19:33:51 -0600

DefiantPanda gravatar image

updated 2018-11-28 19:57:28 -0600

I wanted to redirect my site to https from http. But when I tried to chain the requests I get an error. So instead I have two virtual host entries, one for each alias (www.example.com and example.com):

<VirtualHost *:80>
    DocumentRoot /var/www/example.com/public_html/public
    ServerName www.example.com
    ServerAdmin me@example.com

    ErrorLog /var/www/example.com/logs/error.log
    CustomLog /var/www/example.com/logs/access.log combined

    RewriteEngine on 
       RewriteCond %{SERVER_NAME} =www.example.com
       RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/example.com/public_html/public
    ServerName www.example.com
    ServerAdmin me@example.com

    ErrorLog /var/www/example.com/logs/error.log
    CustomLog /var/www/example.com/logs/access.log combined

    RewriteEngine on 
       RewriteCond %{SERVER_NAME} =example.com
       RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

And that works; it redirects the site to https.

But now I have another problem. I have an app I have installed which takes a URL like www.example.com/something and redirects to some code based on the URI. So basically I need to change www.example.com/something to www.example.com/index.php?path=$1 and then based on what $1 is redirect accordingly. But using this method to redirect to https, that doesn't work.

So is there a better way to redirect both www.example.com and example.com to https without affecting REQUEST_URIs as well?

Any help greatly appreciated.

edit retag flag offensive close merge delete

Comments

You have obscured your code to the point where I can not tell what you are doing. What app is installed? Sounds like php ?

Panther gravatar imagePanther ( 2018-11-28 23:18:19 -0600 )edit

Yeah it is PHP.

DefiantPanda gravatar imageDefiantPanda ( 2018-11-28 23:56:02 -0600 )edit

So post your php code without obscuring or $fixit

Panther gravatar imagePanther ( 2018-11-29 00:12:48 -0600 )edit

There's nothing wrong with the code. It worked on an Ubuntu system but since switching to Fedora it no longer works.

DefiantPanda gravatar imageDefiantPanda ( 2018-11-29 04:32:20 -0600 )edit

Besides. This isn't a PHP site it's a site about Fedora and the software on Fedora.

DefiantPanda gravatar imageDefiantPanda ( 2018-11-29 04:33:16 -0600 )edit