Forum Moderators: phranque

Message Too Old, No Replies

301 Code Tweak

Working, but some tweaks needed

         

jscsi33

6:18 pm on Jun 16, 2006 (gmt 0)



I have the following in my .htaccess and it is working fine, but I would like to tweak it...so [somehost.com...] will also redirect to [somehost.com...] I have tried to archived solutions, but receive 500 errors

RewriteEngine On
RewriteCond %{HTTP_HOST} ^somehost\.com
RewriteCond %{REQUEST_URI} ^/?$ [OR]
RewriteCond %{SERVER_PORT}!443
RewriteRule (.*) [somehost.com...] [R=301,L]

Any help will be appreciated.

Thanks!

jdMorgan

5:07 pm on Jun 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Adding a second rule for HTTPS should work, assuming that HTTPS requests also resolve to the directory where this .htaccess code resides.

RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^example\.com
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^$ http://www.example.com/ [R=301,L]
#
RewriteCond %{HTTP_HOST} ^example\.com
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^$ https://www.example.com/ [R=301,L]

Because your original code only affected requests for "/", I re-coded it to do the same thing in a more efficient way, removing the redundant "RewriteCond %{REQUEST_URI} ^/?$" and moving that URI test to the RewriteRule instead.

Jim