Port 443 and Port 80 Apache

Hi,

My site runs on port 443 but I still want people to be able to access it if they type http:// instead of https://

To that end I have been trying to redirect all http requests to https using this rewrite rule

RewriteEngine On
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^.*$ https://%{SERVER_NAME}[L,R]

However, it doesn’t actually change the url to https://. It loads the page using the DocumentRoot of the https connection but it doesn’t change the URL.

Any ideas?

/Jlar

Yes, your rule is missing something

RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Thanks ken_yap, perhaps you could enlighten me as to what it’s missing… :slight_smile: It looks right…!!

I have been rooting around at this for two months, and I have tried putting rewrite rules in the Apache config, in the root of the web server - everywhere. Nothing works. I have tried countless combinations. I know it’s possible. There are loads of sites that use it.

Any help greatly appreciated…

/jlar

Just eyeball your code and mine and you will see what the difference is.

Yeah I tried adding the %{REQUEST_URI} that is in your code. It didn’t make any difference. I already have a rewrite rule in the htdocs directory which redirects all requests to index.php. I don’t know if that is messing things up…

I finally figured this out… it was all down to a simple directive in the default-server.conf

AllowOverride None

which means all .htaccess is disabled for that directory. The reason it was working in the Virtual host was because I had AllowOverride All for that directory.

/jlar

Thanks ken_yap, perhaps you could enlighten me as to what it’s
missing… :slight_smile: It looks right…!!

I have been rooting around at this for two months, and I have tried
putting rewrite rules in the Apache config, in the root of the web
server - everywhere. Nothing works. I have tried countless combinations.
I know it’s possible. There are loads of sites that use it.

Any help greatly appreciated…

/jlar


eeijlar

eeijlar’s Profile: http://forums.opensuse.org/member.php?userid=1504
View this thread: http://forums.opensuse.org/showthread.php?t=399579

Just eyeball your code and mine and you will see what the difference is.


ken_yap

ken_yap’s Profile: http://forums.opensuse.org/member.php?userid=221
View this thread: http://forums.opensuse.org/showthread.php?t=399579

Yeah I tried adding the %{REQUEST_URI} that is in your code. It didn’t
make any difference. I already have a rewrite rule in the htdocs
directory which redirects all requests to index.php. I don’t know if
that is messing things up…


eeijlar

eeijlar’s Profile: http://forums.opensuse.org/member.php?userid=1504
View this thread: http://forums.opensuse.org/showthread.php?t=399579

I finally figured this out… it was all down to a simple directive in
the default-server.conf

AllowOverride None

which means all .htaccess is disabled for that directory. The reason it
was working in the Virtual host was because I had AllowOverride All for
that directory.

/jlar


eeijlar

eeijlar’s Profile: http://forums.opensuse.org/member.php?userid=1504
View this thread: http://forums.opensuse.org/showthread.php?t=399579