Forum Moderators: phranque

Message Too Old, No Replies

Redirect https://www.example.com to https://example.com

         

ac1982

8:17 am on Sep 5, 2012 (gmt 0)

10+ Year Member



Hi, I am trying to do a simple redirection here but is not working. Redirect all incoming [example.com...] to [example.com,...] anything else coming to HTTP must not be affected. Can anyone advice what is wrong here?

RewriteEngine On
##Redirect [example.com...] to [example.com...]
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ [example.com...] [L,R,NE]

thanks in advance

phranque

8:57 am on Sep 5, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



not working

what response are you getting?
=8)

i would combine the first 2 RewriteCond directives:

RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC]

that pattern means HTTP_HOST is not a null string (handles http 1.0 compatible user agents) and not exactly/entirely www.example.com (case-insensitive)

g1smd

9:16 am on Sep 5, 2012 (gmt 0)

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



The original code:

"If it's not www redirect to non-www."

That matches the pattern again, so you have an infinite loop.

Are you sure you wanted a 302 redirect?

ac1982

9:31 am on Sep 5, 2012 (gmt 0)

10+ Year Member



Question: I currently have a .htaccess in the folder I am trying to access, will this file override any other .htaccess files that are on parent folder correct?

Next I have comment everything except RewriteEngine On in my .htaccess and when I access the folder it redirects me to another folder(I had a rule previously in .htaccess to redirect any file on another folder which now is comment out). Is .htaccess stored in cache as it ignores my .htaccess and make use of old rules that no longer exists in the current file.

ac1982

9:56 am on Sep 5, 2012 (gmt 0)

10+ Year Member



waiting a while after i had comment everything in the .htaccess, now its back to normal, requests to [example.com...] gives an error Untrusted COnnection and [example.com...] displays the page properly.

What I need to do is to redirect traffic from [example.com...] to [example.com?...]


note: i have installed an ssl certificate for example.com and not for www.example.com

lucy24

10:00 am on Sep 5, 2012 (gmt 0)

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



!

That was not an editorial comment. It was an answer to the original question. But g1 already gave you the long version. (Drat these tabs anyway!)

I currently have a .htaccess in the folder I am trying to access, will this file override any other .htaccess files that are on parent folder correct

Apache generally works from top to bottom. So anything in an htaccess file will override the config file-- assuming the config file has allowed the htaccess to do so. But then if you have a second htaccess in a deeper directory, the second one can override the first.

This only applies if a request reaches the htaccess at all. If your first htaccess says Deny from 2.3 and your second htaccess says Allow from 2.3.4, it's too late for your friend at 2.3.4.5 because the request has already been blocked. And if your first htaccess redirects from a to b, and the inner one redirects from a to c, you will never get to c because you've already been sent to b.

Next I have comment everything except RewriteEngine On in my .htaccess and when I access the folder it redirects me to another folder(I had a rule previously in .htaccess to redirect any file on another folder which now is comment out). Is .htaccess stored in cache as it ignores my .htaccess and make use of old rules that no longer exists in the current file.

No, htaccess is not cached at all. Pages can be cached, so your browser might never check with the server and see that the rules have changed. So Step One is to empty your browser cache. Trying a different browser helps too. If this makes no difference, you had better take a closer look and find any stray htaccess files you had forgotten about.

g1smd

10:16 am on Sep 5, 2012 (gmt 0)

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



All htaccess files in the requested path apply, from root to subfolder. To prevent outbreaks of insanity, it is best to put all rules in the root htaccess file.

Redirect responses are cacheable in the browser. The htaccess file is not read by the browser. It is processed by the server. It's a configuration file.

ac1982

10:35 am on Sep 5, 2012 (gmt 0)

10+ Year Member



hey thank u very much for your valuable comments and quick response, i ll check if parent htaccess rules are overriding the child htaccess and I ll see if I can have all the rules in the parent htaccess.

g1smd

10:52 am on Sep 5, 2012 (gmt 0)

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



When you do that, rule ORDER becomes VERY important.

You also must make sure to use directives only from mod_rewrite and not from mod_alias.