PDA

View Full Version : .htaccess RewriteRule



Dr Small
September 17th, 2008, 09:23 PM
I want to be able to rewrite URLs to https IF I am browsing the site with SSL. I have this, but it isn't working:


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

Anyone better at htaccess than me, that could help?

Dr Small

drubin
September 17th, 2008, 11:50 PM
I am not amazing with apache configs but .htaccess should be used as a last resort if you do not have access to the apache config files for this virtual host/server.

.htaccess syntax is exactly the same as the apache syntax. So just a recomendation if at all posible move your ".htaccess" into the apache config.

I will take a look and see what else I can come up with.

ps
Read the point about "When (not) to use .htaccess files"
http://httpd.apache.org/docs/1.3/howto/htaccess.html

Dr Small
September 18th, 2008, 03:10 AM
This isn't on my server. My Dad hosts his website on an remote server, and I was just trying to rewrite the URLs when accessing the site via HTTPS, to https:// for all URLs.

No, this isn't related to my openfire problem ;)

drubin
September 18th, 2008, 11:52 AM
mmm Not even sure a rewrite rule is the best option. Is your dad's site written in a scripting lang?

If yes an answer might be just to change the clients url.

In php juts pop that in a header/common file to all scripts.
http://www.php.net/manual/en/reserved.variables.php#74040

Dr Small
September 18th, 2008, 09:59 PM
mmm Not even sure a rewrite rule is the best option. Is your dad's site written in a scripting lang?

If yes an answer might be just to change the clients url.

In php juts pop that in a header/common file to all scripts.
http://www.php.net/manual/en/reserved.variables.php#74040
Nope. It's all written in HTML... (!Frontpage!)
Anyhow, I may just resort to linking everything throughout the website to relative links instead of complete URLs (http://). Because if it is a relative link, the link automatically gets rewritten when viewing the site with HTTPS.

drubin
September 18th, 2008, 10:39 PM
That might be the best option.

You could even try and replace ALL http://servername.com/ with /. Try a simple replace script that might even work :)

But as with every thing that is more then likely going to break things backup!!

(Mostly for any one else reading this thread, I am sure you would do that any way)

drubin
September 18th, 2008, 10:42 PM
Take a look here.
http://trainofthoughts.org/blog/2007/04/01/jquery-plugin-extlink/ point #9