Forum Moderators: phranque

Message Too Old, No Replies

Apache mod_rewrite and FrontPage extensions

A solution for the widespread incompatibility problem

         

Merlin2000

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

10+ Year Member



I have searched around quite awhile for a fix with the error received when using Apache's RewriteEngine and FrontPage Server Extensions.

It seems that whenever you have

Rewrite Engine On

in your .htaccess, and FPSE are enabled, a 403 error is produced after you submit a form (the form never gets submitted).

The only place I have found that gives a working solution, is found here: [msfrontpage.net...]

However that solution doesn't seem to work, and many articles on the site are outdated. (The author dicusses background fixes for NS 3/4 in one of his posts :P )

jdMorgan

7:42 pm on May 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looping is only of concern in .htaccess, as long as you have some 'conditional' on the redirect, such as your <VirtualHost> container that implements the "IF wrong domain, THEN redirect."

The looping that we usually discuss here can occur in .htaccess due to the fact that any rewritten URL must be passed back through httpd.conf and then through .htaccess files in the new directory path, in order to check for more rewrites and access restrictions -- otherwise, .htaccess could be used to circumvent access restrictions - a major security problem. Therefore, .htaccess code must be coded as if it were 're-entrant' or 'recursive' to avoid loops. That doesn't usually apply to httpd.conf, because it doesn't reinvoke itself.

Jim

Merlin2000

7:47 pm on May 25, 2005 (gmt 0)

10+ Year Member



Ok, but that still would not work, even if it didn't produce the looping error. Is there actually code that I can use that will work?

Btw, I am submitting a bug/support request to rtr.com

chopin2256

2:27 am on May 26, 2005 (gmt 0)

10+ Year Member



Although I still would like an answer to this current problem so I can use hotlink protection...I was thinking, is there any other way to redirect my non-www to www without using the htaccess method?

jdMorgan

3:15 am on May 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Merlin2000,

> Ok, but that still would not work, even if it didn't produce the looping error.

I don't understand. Why do you think it won't work?

--

chopin2256,

You can use mod_alias directives (Redirect or RedirectMatch) in a <VirtualHost> container in httpd.conf. In .htaccess, mod_rewrite is the only module that has the capability of selectively redirecting based on the requested hostname. In httpd.conf, the redirect is conditional upon the <VirtualHost> container, so it will redirect only www- or non-www as specified by the container.

Jim

Merlin2000

4:04 am on May 26, 2005 (gmt 0)

10+ Year Member



I don't understand. Why do you think it won't work?

- When I put it in my .htaccess it produced a loop. Are you saying this will work if it is in the apache config file, and also it will make http://example.com > http://www.example.com and http://example.com/folder/page.html > http://www.example.com/folder/page.html?

[edited by: engine at 11:17 am (utc) on Aug. 26, 2005]

chopin2256

4:45 am on May 26, 2005 (gmt 0)

10+ Year Member



Especially if you have the option to do the rewrites in httpd.conf

I am on a shared server right now. I couldn't find the httpd.conf file. Is it located here?

/etc/httpd/conf/httpd.conf

If so, I did not see it. Would changing to a virtual hosting account grant me this freedom, because it looks like I may have to do this now.

Merlin2000

4:53 am on May 26, 2005 (gmt 0)

10+ Year Member



You wont have access to this because you are on a shared server, but if you contact your host to make the change you might be in luck.

jdMorgan

6:35 am on May 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Merlin2000,

'Unexpected' looping is only a problem in .htaccess, because of the way .htaccess files are processed as described above. With very slight modifications, mod_rewrite code will work in httpd.conf. Or you can use Redirect or RedirectMatch in a <VirtualHost> container or other container to make them conditional .. i.e. only redirect requests for the 'incorrect' domain name.

I'm not sure what you put in your .htaccess this time, but Apache directives are restricted in their use; The documentation for each directive tells you where it can be used. So, if you tried to put a <VirtualHost> or <Directory> container into .htaccess, that would fail with a 500 Server Error. If you tried to use a Redirect directive without making it conditional by enclosing it in a container, then it would loop.

Jim

Merlin2000

5:33 pm on May 26, 2005 (gmt 0)

10+ Year Member



Are you saying this will work if it is in the apache config file, and also it will make http://example.com > http://www.example.com and http://example.com/folder/page.html > http://www.example.com/folder/page.html?

jdMorgan

9:26 pm on May 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't spend a lot of time researching [httpd.apache.org] and testing for you, but something like the following should help:

<VirtualHost www.example.com>
ServerName www.example.com
..the rest
</VirtualHost>

<VirtualHost *>
Redirect 301 / http://www.example.com/
</VirtualHost>

Jim

tr95

3:31 pm on May 31, 2005 (gmt 0)

10+ Year Member



I write all of my sites in FrontPage and long since gave up trying to find a way to redirect non-www to www without breaking the FrontPage extensions. This is something that MS should deal with.

At least if you add a <base href> definition in your page headers, all in-site links on the page will appear with www whether or not the page was opened with www, ie: <base href="http://www.example.com">.

TheRookie

3:02 am on Jun 2, 2005 (gmt 0)

10+ Year Member



Just here to chime in that I'm having the same problem as you guys. Hoping to find an answer...

chopin2256

2:15 am on Jun 13, 2005 (gmt 0)

10+ Year Member



There is finally a fix to this annoying problem. "Bumpski" had brought this to my attention, I will just be the messanger.

If you are using the redirecting code...this is what you use in the htaccess file directly under the www folder:

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Then replace:

"Options None" with "Options +FollowSymLinks" in every single htaccess file that you can find. There will only be about 7 of these files according to the subdirectories I listed below. Here are some subdirectories where they may be found:

_vti_bin (_vti_adm, _vti_aut)
_vti_cnf
_vti_log
_vti_pvt
_vti_txt

Remember, if you replace the Options None with Options +FollowSymLinks in every single one of these htaccess files, you should be able to connect to the server with Frontpage.

Again, thanks goes to Bumpski for bringing this to my attention.

Hope this helps others having the same problem.

steveb

2:43 am on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This hasn't had an answer for a long time, and this also works:

RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteCond %{http_host} ^(example+\.com) [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

I used to use the code chopin has above, but just went an did it with
RewriteCond %{http_host} ^(example+\.com) [NC]
instead of
RewriteCond %{HTTP_HOST} ^example\.com [NC]

Any downside in what I used? It does work with the parentheses, but I'm clueless about this stuff so if someone who understands this stuff, even if they don't know frontpage, could comment about the sense of that specific code in .htaccess, that would be cool.

(Also, I only altered the None in _vti_bin (_vti_adm, _vti_aut) not any of the others, and FP and the redirect worked.)

Merlin2000

2:57 am on Jun 13, 2005 (gmt 0)

10+ Year Member



Can anyone add a FrontPage Form to their working version now just to make sure it has fixed everything?

Btw, if you look at my first post, I link over to [msfrontpage.net...]

which discusses the fix, but it didn't seem to work for me.

jdMorgan

3:16 am on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



steveb,

A correct-case and minimalist solution would be written:


RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

In order to prevent obscure problems, I suggest paying close attention to the uppercase/lowercase/CaMeLcAsE specified in the documentation. I've seen at least one recent report of a failure due to incorrect server variable case.

Parentheses are only needed to
1) create a back-reference
2) enclose a list of alternates: ^(abc¦def¦ghi)$
3) enclose an optional substring: ^(www\.)?example\.com

I'd appreciate it if everyone who's had problems with mod_rewrite and Frontpage Extensions would post back here and let us know if this solution fixes your problem. It seems there's little info on the Web about it, and the problem seems to be widespread.

Jim

Merlin2000

5:26 am on Jun 13, 2005 (gmt 0)

10+ Year Member



I finally had a few minutes and this fixed my problem. Glad I can use FrontPage Forms again!

Simply add Options +FollowSymLinks to your main .htaccess file, then each FrontPage created folder's .htaccess file needs Option None changed to Options +FollowSymLinks.

There are quite a few needed to be changed, I found more than 7.

Merlin2000

5:47 am on Jun 13, 2005 (gmt 0)

10+ Year Member



Hmmm.. It looks like there isn't a 403 error anymore on form submissions, however forms do NOT send e-mailed results.

steveb

5:56 am on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Jim.

The Frontpage publishing and Deep Throat mysteries revealed in the same month. Who would have thunk it...

Anyway, I just switched to:

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

And it worked with no problems. Again, I only also made the +FollowSymLinks change to the _vti_bin and its two subfolders, not all the Frontpage underscore folders.

Also, in addition to the www redirect, I have code in .htaccess to prevent hotlinking, and having that additional code doesn't create a problem with this fix in place.

Finally, is their a brief answer for what "+FollowSymLinks" means? I mean, follow the links from directoryies, okay, but what does it mean in this context?

jdMorgan

6:13 am on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In order to use mod_rewrite, either FollowSymLinks or SymLinksIfOwnerMatch must be enabled. If not, you'll get a 500-Server Error and a message in your error log which specifically tells you to enable either Option.

I'm not sure if mod_rewrite actually requires SymLinks, or if they are simply considered to have very similar "security" effects, and therefore arrangements were made to share the on/off controls.

Jim

tr95

12:58 am on Jun 14, 2005 (gmt 0)

10+ Year Member



I simply want to confirm where to place the lines of Rewrite code in .htaccess. My main .htaccess file looks like this:

# -FrontPage-

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
#The next line modified by DenyIP
order allow,deny
#The next line modified by DenyIP
#deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.example.com
AuthUserFile /home/example/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/example/public_html/_vti_pvt/service.grp

<Files 403.shtml>
order allow,deny
allow from all
</Files>

deny from nn.nn.nn.nnn
deny etc.

-------

In the .htaccess files in my _vti directories, the Options line looks like this:

Options None All -Indexes

So in this line, is it correct that None would be replaced with +FollowSymLinks?

jdMorgan

2:29 am on Jun 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"Options None All -Indexes" doesn't make sense. Specifically, following "None" with "All" negates the need for "None" since they are opposites.

If you put "Options All -Indexes" that should be equivalent.

The end result either way is that FollowSymLinks would be enabled, because it's included in "All".

Options [httpd.apache.org] documentation.

Jim

Merlin2000

3:28 am on Jun 14, 2005 (gmt 0)

10+ Year Member



Can anyone try to submit a FrontPage form that sends an e-mail, and then check to make sure the e-mail comes?

biggles

11:39 pm on Jun 29, 2005 (gmt 0)

10+ Year Member



Hi Jim - you asked if everyone who's had problems with mod_rewrite and Frontpage Extensions would post back here and advise if this solution fixes your problem.

It does! I'd been wrestling with this unsuccessfully & had given up, so a sincere thank you to you, chopin 2256, & steveb.

The specific rewrite code I used to get http://example.co.nz to re-direct to www.example.co.nz is:

<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.co.\nz [NC]
RewriteRule ^(.*)$ http://www.examplez.co.nz/$1 [L,R=301]

As steveb suggested I only needed to change the "Options None" to "Options +FollowSymLinks" just in each of the htaccess files of the 3 following FP directories only:

_vti_bin ; _vti_bin /_vti_adm ;& _vti_bin/ _vti_aut

The one outstanding issue I couldn't resolve & hopefully you can assist with is getting www.example.co.nz/index.htm to resolve to www.example.co.nz/.

To do this I tried adding RewriteRule ^index.html$ / [R=301,L] to the above Mod Rewriite code but it broke the re-direction because the server gets into an endless redirection loop.

<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.co.\nz [NC]
RewriteRule ^(.*)$ http://www.examplez.co.nz/$1 [L,R=301]
^index.html$ / [R=301,L]

Anyone able to point out what I'm doing wrong here please?

Many thanks.

[edited by: engine at 11:21 am (utc) on Aug. 26, 2005]

biggles

11:31 pm on Jun 30, 2005 (gmt 0)

10+ Year Member



Bump...

I'm wondering if the problem above is due to a syntax error in the last line of the mod rewrite code.

Could someone who knows about this please suggest any changes that need to be made.

Thanks in advance

andy_boyd

12:55 am on Jul 1, 2005 (gmt 0)

10+ Year Member



I'm still having problems getting http://www.example.com/index.html to redirect to www.example.com/ ....

Does anyone have any tips?

jdMorgan

12:57 am on Jul 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



biggles,

Sorry, I saw andy_boyd's thread first: [webmasterworld.com...]

Jim

This 57 message thread spans 2 pages: 57