Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Aug 20, 2013 12:30 am 
Offline
Senior Newbie

Joined: Tue Aug 20, 2013 12:16 am
Posts: 6
Hello
I use the following .httaccess rule for removing index.php from URI and it works well for http requests.
Code:
RewriteRule ^(.*)$ index.php/$1 [PT,L]


I want to move all comunication to https using ssl certificate, but when I redirect the browser to https://...
the rewrite rule don't work any more. If I add index.php the request is succesfull. How to change RewriteRule to work with HTTPS?

Thanks


Top
   
PostPosted: Tue Aug 20, 2013 12:41 am 
Offline
Senior Newbie

Joined: Tue Aug 20, 2013 12:16 am
Posts: 6
Solved. I had to enable in vhost.conf
Code:
 AllowOverride All 


Top
   
PostPosted: Tue Aug 20, 2013 3:22 am 
Offline
Senior Newbie

Joined: Tue Aug 20, 2013 12:16 am
Posts: 6
Got another problem. I want to force all connection to use https.
Here is my full httaccess
Code:
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On

# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /

# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)

# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]

# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|opensearch\.xml|favicon\.ico|public|js|css)

# No rewriting
RewriteRule ^(.*)$ - [PT,L]

# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
 

</IfModule>


Here is my vhost.conf
Code:
NameVirtualHost 127.0.0.2:443

<VirtualHost 127.0.0.2:443>   # not the real ip
    SSLEngine On
    SSLCertificateFile /etc/httpd/ssl/httpd.pem
    SSLCertificateKeyFile /etc/httpd/ssl/httpd.key

    ServerAdmin admin@mysite.com
    ServerName  mysite.com
    ServerAlias www.mysite.com
    ErrorLog    /web/errors/mysite
    DocumentRoot /web/myb/htdocs
    <Directory "/web/myb/htdocs">
       Options FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from all
    </Directory>-
</VirtualHost>


If I access the site using https://mysite.com it works and access over https using ssl
If I enter mysite.com on browser it is redirected to /var/www/html

My little workaround is to put an index.php with the content :
Code:
if(empty($_SERVER["HTTPS"])) {
    $newurl = "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
    header("Location: $newurl");
    exit();
}


I tried some .httaccess redirect solutions but didn't work. I prefer not put them here because I was doing copy-paste without understanding them and is posible that some of my .httaccess file content to conflict with redirect rules.
BR


Top
   
PostPosted: Tue Aug 20, 2013 3:35 am 
Offline
Senior Member

Joined: Sun Apr 26, 2009 3:37 am
Posts: 72
Website: http://wiggenhorn.org/
You could add a non-SSL virtual host that redirects visitors to the SSL virtual host. For example:

Code:
<VirtualHost *:80>

        ServerName domain.com
        ServerAlias www.domain.com
        ServerAdmin you@domain.com

        Redirect permanent / https://www.domain.com/

</VirtualHost>


Top
   
PostPosted: Thu Aug 29, 2013 12:57 am 
Offline
Senior Newbie

Joined: Tue Aug 20, 2013 12:16 am
Posts: 6
Thanks for reply, I was caught with some urgent matters, just tested and works like a charm.

BR


Top
   
PostPosted: Thu Aug 29, 2013 2:03 am 
Offline
Senior Member
User avatar

Joined: Thu Nov 24, 2011 12:46 pm
Posts: 139
Location: Mesa AZ
I create a general vhosts for all my http to https sites...

vhosts
Code:
# Redirect Hosts to SSL if they SSL Sites
<VirtualHost *:80>
    ServerAdmin     "webmaster at tnet.com"
    DocumentRoot    /www/vhosts/http-redirect
    ServerName      www.domain1.com
    ServerAlias     special.domain2.com
    ServerAlias     www.domain3.com
    ErrorLog        logs/http-redirect.errors
    CustomLog       logs/http-redirect.combined combined
</VirtualHost>


.htaccess
Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


Might not be the best way, but it was a quick and dirty way that I just used when I got a wildcard SSL and started moving a number of sites. Gives me a log of who is hitting the http sites so that I can update a page if it has an old link.

_________________
Kevin a.k.a. Dweeber


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group