Need some .htaccess / mod_rewrite help :)

Started by tallship, September 09, 2013, 09:24:50 AM

tallship

I'm currently configured w/the SEO URL settings of

Settings ==> General ==> Other ==> SEO URLs settings ==> Apache Mod Rewrite

I've implemented this no prob w/my .htaccess using the following mod_rewrite rules like so:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^downloads/?$ ?cmd=downloads [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>


Everything works fine like this. URLs are nice, no index.php or question marks, etc.

But I want to force everyone going to http://sld.tld to https://sld.tld

I have the following two code snippets, and I'm not sure which is the best way to implement this:


RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


and


RewriteEngine On
RewriteCond %{SERVER_PORT}80
RewriteRule ^(.*)$ https://sld.tld/$1 [R=301,L]


I'm not sure which way to go...

I've tried the following, but it breaks the site:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule ^downloads/?$ ?cmd=downloads [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>


I shouldn't need the IfModule tags and I don't think I need the "RewriteBase /" line either, and have tried w/and w/o them.

The other code snippet specifies a 301 and I'm hesitant to use that because of the permanent redirect for SEO purposes and whether it will hurt me telling the search engines to only use SSL.

What have others done here and what are some suggestions for forcing SSL? If you don't enforce SSL... Why not? I'm interested in hearing all the in's and out's on this topic and figured it would be best for security reasons just to force everyone into using SSL but there may be other, more compelling reasons why not to.

I remember some threads from the forums that were nuked by kbkp talking about changing each and every instance of something in the templates but that sounds like a lot of work for no real reason, and would like to know what everyone else is doing for their installs.

Thanks :)
Bradley D. Thornton - Manager Network Services, NorthTech Computer   TEL: +1.310.388.9469 (US) | +44.203.318.2755 (UK) | +61.390.088.072 (AU) | +41.43.508.05.10 (CH)
Registered Linux User #190795 - "Ask Bill why the string in [MS-DOS] function 9 is terminated by a dollar sign. Ask him, because he can't answer. Only I know that." - Dr. Gary Kildall.

davemarks

It's actually simple. I use this in the .htaccess file in the HB root. Similar to your second snippet. I use %{SERVER_NAME} since I want all requests to have the www in front.

RewriteCond %{SERVER_PORT} 80$
RewriteRule ^(.*)$ https://www.%{SERVER_NAME}/HB_DIR/$1 [L,R=301]

The 301 is fine, since anyway the link will only be accessible via SSL. Google will still index it. You could use 302 for temporary redirects but it's not really temporary ;D

Fusionhost

fusionhost - www.fusionhost.co.uk
Leading British Cloud Web Hosting Provider