Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!


Are you a Google Analytics enthusiast?

Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE! 




From the folks who brought you High Rankings!

- - - - -

Can Someone Check My Code? - Amateur Programmer Using Htaccess For The

  • Please log in to reply
3 replies to this topic

#1 Noor


    HR 1

  • Members
  • Pip
  • 3 posts
  • Location:New Mexico

Posted 04 May 2012 - 02:05 AM

Hello everyone,

First, this site seems awesome, and I want you to know that I was directly forwarded here from the tech support of my service provider, so sounds like you guys are pretty well-known. I hope you can help a pretty amateur programmer and webmaster work through what I need to do with .htaccess.

Our website is [removed as unecessary], and long story short, the whole thing started when Google randomly decided to index a few of our pages as https instead of http, and people didn't want to go to them because their browsers would warn them that the pages weren't secure (of course they weren't, they weren't supposed to be). So I started a journey to figure out how to fix that. Within that journey I also figured out that it would be good to redirect all http:// to http://www. So now I am trying to do both of those things, and based on what I have read in this forum and other places, sounds like .htaccess is the best way to do both.

First question is: Our server is not *nix but IIS 6 - however they do support the ISAPI Rewrite Filter. I could not find much information on your forums on how to use .htaccess for IIS, but I did come across one post saying that with ISAPI, you can pretty much use the same code as you would for mod_rewrite because it is based off of that. So that is what I am doing - I hope that will work, please let me know if not and I need a different approach.

With that said, I am copying code from 3 posts and trying to adapt them to my situation:

1. http to www - http://www.highranki...dpost__p__60341

2. https to http - http://www.highranki...post__p__283267

3. setting up a special robots.txt file to disallow any further https crawling: http://www.highranki...post__p__298856

So: I want my .htaccess file to 1) redirect all http to www, 2) all https to http EXCEPT for one folder maitreya.org/store where our e-commerce is, and 3) make the special robots.txt file work so no more https can be spidered. Here is what I have so far:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^maitreya\.org
RewriteRule ^(.*)$ [url="http://www.site.tld/$1"]http://www.site.tld/$1[/url] [R=permanent,L]

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^/store/^
RewriteRule ^(.*)$ [url="http://site.tld/$1"]http://site.tld/$1[/url] [R=301,L]

RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^robots.txt$ robots_ssl.txt

So how am I doing so far? For example, do I need to put "Options +FollowSymLinks" and "RewriteEngine on" twice, or can i remove one? And I sort of guessed with creating the exception for the /store/ folder, did I guess correectly? Any help would be most appreciated. Thanks very much!


#2 chrishirst


    A not so moderate moderator.

  • Moderator
  • 7,718 posts
  • Location:Blackpool UK

Posted 04 May 2012 - 03:59 AM

You will need to check if REQUEST_URI is returning a value as it is not necessarily supported on IIS


#3 Noor


    HR 1

  • Members
  • Pip
  • 3 posts
  • Location:New Mexico

Posted 06 May 2012 - 12:03 PM

Thanks chrishirst for your answer. Indeed I checked with our service provider and they do not accept REQUEST_URI, so i replaced it with the HTTP_X_REWRITE_URL workaround you linked me. Unfortunately, however, this part is still not working. It is supposed to exclude our e-commerce from the https -> http redirection, but I just tested it and right now our e-commerce is never moving to secure connection, even through checkout. Clearly this is a big problem. I have a feeling it is because my code is wrong. Can someone double check that specific part and tell me if what I am doing is making sense, this is the only part I did not copy from someone smarter than me but tried to guess myself :). Again, that part is:

RewriteCond %{SERVER_PORT} ^443$
[b]RewriteCond %{HTTP_X_REWRITE_URL} !^/store/^[/b]
RewriteRule ^(.*)$ http://example.org/$1 [R=301,L]

Thanks very much!

Everything else is working great, by the way, this is the only part that is still messed up. After I have everything working 100% I am planning on copying my code exactly so if other amateurs find this forum post it might help them.

#4 Noor


    HR 1

  • Members
  • Pip
  • 3 posts
  • Location:New Mexico

Posted 16 May 2012 - 11:13 PM

Wanted to follow up in case any other people find this thread while searching:

I ended up kind of giving up, because I kept causing more problems than I was fixing. However, I can offer two pieces of excellent code which were given to me on another forum which definitely worked for me 100% (so they worked on IIS with ISAPI_Rewrite for me, and should also work on *nix I believe):

1. Redirect all .index pages in folders (any case, .INDEX, .Index, etc.) to the folder base (so example/index.htm redirects to example/):

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html? [NC]
RewriteRule ^(([^/]+/)*)index\.html?$ [url="http://example.com/$1"]http://example.com/$1[/url] [R=301,L,NC]

2. Redirect all www to non-www (so www.example.org redirects to example.org - this should also be able to be adapted to redirect non-www to www by a little tweaking, not sure what that tweaking would be though):

RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteRule (.*) [url="http://example.com/$1"]http://example.com/$1[/url] [R=301,L]

I hope this helps someone else in the future. Thanks for the help.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

We are now a read-only forum.
No new posts or registrations allowed.