Forum Moderators: phranque

Message Too Old, No Replies

Problem with conflicting rewrite rules

301 redirect,https:// to http://www,seo,htaccess,joomla

         

dirtymonkey

11:37 pm on Mar 7, 2009 (gmt 0)

10+ Year Member


Apache/2.2.3 (Debian)
Control Panel Plesk
Environment Joomla 1.5.9

Hi,

I am having problems configuring .htaccess. The first rewrite rule for http:// to http://www seems to work fine but the https:// to http://www doesn't seem to.

I have 'Force SSL' enabled for the 'Administrator only' in Joomla but when I try and login I am getting thrown back to the login screen.

I'm wondering if these rules are conflicting somehow... can anyone confirm that this should work or suggest a fix.

Thanks in advance, DM.

--
########## Begin - Rewrite rules to enhance SEO SEF
#
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain/$1 [R=301,L]
#
RewriteCond %{HTTPS_HOST} ^mydomain.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain/$1 [R=301,L]
#
########## End - Rewrite rules to enhance SEO SEF
--

dirtymonkey

4:56 pm on Mar 8, 2009 (gmt 0)

10+ Year Member



No replies as yet, perhaps I can clarify my problem better... let me try again.

I am having problems configuring .htaccess

I want to direct traffic for http:// to [www....] I also want to direct traffic for https:// to [www....] at the same time.

Apache/2.2.3 (Debian)
Control Panel Plesk
Environment Joomla 1.5.9

So far I have:

########## Begin - Rewrite rules to enhance SEO SEF
#
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain/$1 [R=301,L]
#
RewriteCond %{HTTPS_HOST} ^mydomain.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain/$1 [R=301,L]
#
########## End - Rewrite rules to enhance SEO SEF

When I 'Force SSL' enabled for the 'Administrator only' in Joomla and go to the admin login page [www ]. and try and login I am getting thrown back to the login screen under [www....]

I'm wondering if these rules should work? or are conflicting? or there is a bug in Joomla?

Thanks in advance, DM.

jdMorgan

7:46 pm on Mar 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like you may have "invented" a variable, there -- HTTPS_HOST is not defined in the mod_rewrite documentation...

One rule is all you really need, as long as that rule takes the current http/https protocol into account:


RewriteCond %{HTTP_HOST} ^example\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com\. [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com:[0-9] [NC]
RewriteCond %{SERVER_PORT}>s ^(443>(s)¦80>s)$
RewriteRule (.*) http%2://www.example.com/$1 [R=301,L]

Note that the ">" character is totally arbitrary, and is just used to make the code clearer and to allow unambiguous parsing of the two variables.

This modified rule also correct requests made with FQDNs or with a port number appended to the hostname.

Important: Replace the broken pipe character "¦" in the RewriteCond pattern with a solid pipe character before use; Posting on this forum modifies the pipe characters.

Jim

g1smd

8:42 pm on Mar 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You might need to put a negative match RewriteCond for the admin folder before the rule to stop the rule running for the Admin folder.

[edit]jd posted while the tab was open.[/edit]

dirtymonkey

4:07 pm on Mar 9, 2009 (gmt 0)

10+ Year Member



I'm really sorry Jim, I just noticed a typo in my posting!

I want to direct traffic for http:// to [www....] I also want to direct traffic for https:// to https://www. at the same time.

Thanks in advance, DM.

dirtymonkey

8:59 am on Mar 11, 2009 (gmt 0)

10+ Year Member



Oops sorry Jim it seems I made a typo!

I want to direct traffic for http:// to [www....] I also want to direct traffic for https:// to https://www. at the same time.

What do I need to modify on your example to get this to work?

RewriteCond %{HTTP_HOST} ^example\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com\. [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com:[0-9] [NC]
RewriteCond %{SERVER_PORT}>s ^(443>(s)¦80>s)$
RewriteRule (.*) http%2://www.example.com/$1 [R=301,L]

Kind regards, DM.

jdMorgan

1:10 pm on Mar 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Test the code exactly as posted above.

Jim

dirtymonkey

2:00 pm on Mar 11, 2009 (gmt 0)

10+ Year Member



Hi Jim,

Tested and http certainly works.

Not 100% sure how https should behave, It does redirect correctly but I get a SSL cert exception error. My cert being for www.mysite.com not mysite.com.

Is this exception normal or should the redirect/rewrite overcome this?

DM.

jdMorgan

2:40 pm on Mar 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't fool SSL certs with any redirect or rewrite. Either expand the cert to cover both domain variants, or consider a self-signed cert for mysite.com.

Jim

dirtymonkey

3:31 pm on Mar 11, 2009 (gmt 0)

10+ Year Member



Then my .htaccess is working and I'm chuffed to nuts!

Thanks again Jim, DM.