Forum Moderators: phranque

Message Too Old, No Replies

Advanced rewrite rules

Advanced rewrite rules

         

Merlin2000

1:28 am on Apr 17, 2005 (gmt 0)

10+ Year Member


After inserting this into my .htaccess for http://www.domain.com/secure/.htaccess

RewriteEngine On
RewriteCond %{SERVER_PORT}!^443$ [OR]
RewriteCond %{HTTP_HOST}!^www\.domain\.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/secure/$1 [R,L]

I goto http://www.domain.com/secure/ and it takes me to https://www.domain.com/secure/

However, when I go to http://www.domain.com/secure

It redirects me to https://www.domain.com/secure//home/username/public_html/secure

Also, when I goto http://www.domain.com/secure/anotherpage

It takes me to https://www.domain.com/secure/anotherpage
which is correct.

I basically want to make all URLs on the /secure folder to use https instead of http.

--
Also, I would like to make a condition, where when the address is http://www.domain.com/secure/another-page-thats-not-secure.php to not rewrite to https

This is just one page that needs to be unsecure.

claus

9:54 pm on Apr 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay, that was a totally stupid error, sorry about that. The reason for that loop is in the two last rewrite rules - they will need a slash at the end of course, otherwise they just don't add the slash to the URL... duh! Here's the full file again, with the changes:

------------------------------------------ 
#turn on the engine
RewriteEngine On

#first, correct the www if necessary
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301]

#then, rewrite secure folder 1
RewriteCond %{REQUEST_URI} !^/helpdesk/admin/parser.php [NC]
RewriteCond %{REQUEST_URI} ^/helpdesk/ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ [domain.com...] [R=301,L]

#then, rewrite secure folder 2
RewriteCond %{REQUEST_URI} ^/modernbill/ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ [domain.com...] [R=301,L]

#then, rewrite slashes for secure folder 1
RewriteCond %{REQUEST_URI} ^/helpdesk [NC]
RewriteCond %{REQUEST_URI} !^/helpdesk/ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]

#then, rewrite slashes for secure folder 2
RewriteCond %{REQUEST_URI} ^/modernbill [NC]
RewriteCond %{REQUEST_URI} !^/modernbill/ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
------------------------------------------

Merlin2000

10:05 pm on Apr 17, 2005 (gmt 0)

10+ Year Member



I updated the htaccess.txt file again to show what I am using.

And it works!

[domain.com...] > [domain.com...]

[domain.com...] > [domain.com...]

--
Oh, and thanks for the help claus :)

claus

10:17 pm on Apr 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Great, and congrats - i just didn't understand why it kept failing until i spotted that stupid error from msg #31. Sometimes little things makes a lot of difference :)

Merlin2000

1:53 am on May 1, 2005 (gmt 0)

10+ Year Member



Ok, one more issue that I just noticed.

FrontPage forms will not work when this is on. The problem occurs with the _vti_bin/ folder.

If I comment out all of the code (except for the RewriteEngine On part) the script still fails.

So basically only when the RewriteEngine is on, it will fail. If I turn it off, it works fine.

Any work around for this?

claus

11:52 am on May 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If this is really due to the rewrite engine being turned on then i don't know how to fix it. In that case, this would be something Frontpage-specific, so you might get better help by asking a question in the Microsoft Related [webmasterworld.com] forum.

If, OTOH, it is a conflict of rules, then you could add this condition to the top of all the blocks of rules:

RewriteCond  %{REQUEST_URI}  !^/_vti_bin  [NC] 

Example:

---------------------------------------------- 
#then, rewrite secure folder 1
RewriteCond %{REQUEST_URI} !^/_vti_bin [NC]
RewriteCond %{REQUEST_URI} !^/helpdesk/admin/parser.php [NC]
RewriteCond %{REQUEST_URI} ^/helpdesk/ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
----------------------------------------------

This simply says that the rewrite rule should not work for an URL that starts with "your-domain.com/_vti_bin".

Merlin2000

8:34 pm on May 1, 2005 (gmt 0)

10+ Year Member



Actually I have verified it is an issue with using RewriteEngine On while running FPSE.

Merlin2000

10:02 pm on May 1, 2005 (gmt 0)

10+ Year Member



I'll make a new post, as this thread's topic is a bit different. I didn't see a forum for FPSE, only Windows OS.
This 37 message thread spans 2 pages: 37