www, non-www, https

Jul 9, 2009 at 5:07 AM

I have tried to look for following but could never understand the syntaxes for redirection or if they are possible.

For 301 redirection for:

http://domain.com/abc.asp?category=mo -> http://www.domain.com/monthly-items.html
- Looking for redirection with WWW

https://domain.com/abc.asp?category=mo -> http://www.domain.com/monthly-items.html 
- Looking for redirection with WWW and without https, or secure

Any help would be great.



Jul 9, 2009 at 2:02 PM
Edited Jul 9, 2009 at 2:07 PM
  RewriteCond %{SERVER_NAME}               ^domain\.com$                               [I]
  RedirectRule ^/abc\.asp\?category=mo$    http://www.domain.com/monthly-items.html    [U,I,R=301]

The above rule redirects to http://www.domain.com/monthly-items.html, with http code = 301, if the incoming request is for /abc.asp?category=mo, AND if the server name used in the request was domain.com.  It does not matter if the incoming request was https or http - in either case the request is redirected to the alternate endpoint. if you use a server name of www.domain.com in the initial request, then it will not be redirected.

I know you said you had trouble with the syntax, but there are examples of exactly this, in the readme.

Jul 11, 2009 at 3:36 AM

Thanks for the help. I will try and will post back here. I could't find any sample with "RedirectRule".

Nov 11, 2009 at 1:36 AM

Finally i tried with the following, but still having problems.

RewriteLog C:\iirf\iirf1
RewriteLogLevel 2
RewriteFilterPriority HIGH

# ------ Monthly items
# REWRITE so that the correct page executes when /monthly-items is the URL
RewriteRule ^/monthly-items.html$ /category1.asp?category=mo [L]

RewriteCond %{SERVER_NAME} ^domain\.com$ [OR]
RewriteCond %{SERVER_NAME} ^www.domain\.com$ [I]
RedirectRule ^/category\.asp\?category=mo$ http://www.domain.com/monthly-items.html [U,I,R=301]

# ----- Fathers day items
RewriteRule ^/fathers-day-items.html$ /category1.asp?category=fd [L]

RewriteCond %{SERVER_NAME} ^domain\.com$ [I]
RedirectRule ^/category\.asp\?category=fd$ http://www.domain.com/fathers-day-items.html [U,I,R=301]

RewriteCond %{SERVER_NAME} ^www.domain\.com$ [I]
RedirectRule ^/category\.asp\?category=fd$ http://www.domain.com/fathers-day-items.html [U,I,R=301]


Here is what i am trying to achieve:

https://www.domain.com/monthly-items.html -> It should rewrite (server side execute) category1.asp page (/category1.asp?category=mo). This is working fine and returning status 200 as expected.

https://domain.com/monthly-items.html -> Should be redirected to http://www.domain.com/monthly-items.html (with a 301 status - meaning all requests to monthly-items.html should go to that page, irrespective of user types in https, http and with or without www.

http://www.domain.com/category.asp?category=mo -> Redirect to http://www.domain.com/monthly-items.html with a status of 301.

https://domain.com/category.asp?category=mo -> Redirect to http://www.domain.com/monthly-items.html with a status of 301. (This one giving an error and not redirecting)

https://www.domain.com/category.asp?category=mo -> Redirect to http://www.domain.com/monthly-items.html with a status of 301. (This one is working fine)


Would you help me as to what i am doing wrong?



Nov 11, 2009 at 8:28 AM


# Rule 1. Map Clean URL to actual asp page
# rewrite https://www.domain.com/monthly-items.html -> 
#    https://server/category1.asp?category=mo 

RewriteCond %{HTTPS} ^on$
RewriteRule ^/monthly-items.html$ /category1.asp?category=mo [L]

# Rule 2.  Always use https for monthly-items
# http -> Redirect to https 

RewriteCond %{HTTPS} ^off$
RedirectRule ^/monthly-items.html$ https://www.server.com/monthly-items.html  [R=301]

# Rule 3.  Always use www prefix 
# domain.com -> Redirect to www.domain.com

RewriteCond %{SERVER_NAME} !^www\.domain\.com$
RedirectRule ^/(.*)$    https://www.domain.com/$1  [R=301]

# Rule 4. Always use clean URL externally
# ugly URL to clean URL
# Eg, redirect  http://anything/category1.asp?category=mo  to  
#                https://www.server.com/monthly-items.html

RedirectRule ^/category1\.asp\?category=mo$  https://www.server.com/monthly-items.html  [R=301]

Nov 12, 2009 at 1:28 AM
Edited Nov 12, 2009 at 2:01 AM

Thanks for the quick response. Understood somewhat better and now close to solution, but still couple of them not working. I have pasted what redirection or rewrites i am looking for. All requests for this particular page only should always go to http://, it is the other way round. Not for the entire server. Sorry if my earlier post above wasn't clear enough.

Request URL Browser address bar - Redirect Status  
http://www.server.com/category.asp?category=mo http://www.server.com/monthly-items.html 301  
http://server.com/category.asp?category=mo http://www.server.com/monthly-items.html 301  
https://www.server.com/category.asp?category=mo http://www.server.com/monthly-items.html 301  
https://server.com/category.asp?category=mo http://www.server.com/monthly-items.html 301 Not working
http://www.server.com/monthly-items.html http://www.server.com/monthly-items.html 200  
https://www.server.com/monthly-items.html http://www.server.com/monthly-items.html 301  
http://server.com/monthly-items.html http://www.server.com/monthly-items.html 301 Not working
https://server.com/monthly-items.html http://www.server.com/monthly-items.html 301 Not working

and here is what's in the .ini

# ------ Monthly items
# REWRITE so that the correct page executes when /monthly-items is the URL
RewriteCond %{HTTPS} ^off$
RewriteRule ^/monthly-items.html$ /category1.asp?category=mo [L]

RewriteCond %{HTTPS} ^on$
RedirectRule ^/monthly-items.html$ http://www.server.com/monthly-items.html  [R=301]

RewriteCond %{SERVER_NAME} !^www\.server\.com$
RedirectRule ^/category\.asp\?category=mo$ http://www.server.com/monthly-items.html [U,I,R=301]




Nov 12, 2009 at 3:10 PM

Few more updates to the above question:


These two are now behaving properly, the issue was more of certificate issue then redirect. Since the certificate issued is to www.server... and not the non www version. One more issue remained, which is

http://server.com/monthly-items.html - This one is not getting redirected to http://www.server.com/monthly-items.html