https httaccess index.php
I use the following .httaccess rule for removing index.php from URI and it works well for http requests.
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
5 Replies
AllowOverride All
Here is my full httaccess
<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
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
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 :
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
<virtualhost *:80="">ServerName domain.com
ServerAlias www.domain.com
ServerAdmin you@domain.com
Redirect permanent / https://www.domain.com/</virtualhost>
BR
vhosts
# 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
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.