.htaccess - HELP NEEDED PLEASE ON REDIRECT
garryhs
Status: New User - Welcome
Joined: 17 Mar 2005
Posts: 1
Reply Quote
Hi,

Does anyone know how to redirect the following.

If
http://www.mydomain.com
is selected, I want to redirect in .htaccess to
http://mydomain.com

and on the same domain, if
https://www.mydomain.com
is selected, I want to redirect in .htaccess to
https://mydomain.com

I want to do this, as my SSL certificate is for mydomain.com and not www.mydomain.com, and I do not want any warnings.

Thanks

Garry
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Somebody asked a related question in this thread

:: Code ::
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mysite\.com
RewriteRule ^(.*)$ http ://mysite.com/$1 [R=301]
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ https ://mysite.com/$1 [R=301,L]

Rewrite stuff is pretty hard, this thread on webmasterworld may help too, it has some more links [you may need to be logged in with an account there to view the thread because wmw doesn't allow direct linking to threads].

The 'L' means it's the last condition to run if true, if you have more rewrite rules after that you'd have to change that.

The basic idea is this, I don't know if this is right or not though: if the domain of your site is requested as www.yoursite.com change it to http ://yoursite.com. If the port being requested is the secure port 443, then redirect to https: //yoursite.com

Note, I added a space between the http and the :, so if you cut and paste this, get rid of that space. No promises though.

No guarantees on this, note the comments on httpd.conf versus .htaccess:

:: Quote ::
the difference is that in httpd.conf, the URL-paths seen by RewriteRule start with a slash, whereas in .htaccess, they don't have the leading slash.

Back to top
Display posts from previous:   

All times are GMT - 8 Hours