Forum Moderators: phranque

Message Too Old, No Replies

Removing .html from "$DOCUMENT NAME"

Is isolating the prefix without the suffix possible.

         

4thePegeh

5:33 am on Mar 21, 2007 (gmt 0)

10+ Year Member




Currently I think I must use several sections such as the following in a file:

<!--#set var="reqfile" value="$DOCUMENT_NAME" -->
<!--#if expr="$reqfile = exbkeywds.html" -->
<!--#include virtual="exbkeywds.txt"-->
<!--#elif expr="$reqfile = duh.html" -->
<!--#include virtual="duhkeywds.txt"-->
<!--#elif expr="$reqfile = exckeywds.html" -->
<!--#include virtual="exckeywds.txt"-->
<!--#elif expr="$reqfile = exdkeywds.html" -->
<!--#include virtual="exdkeywds.txt"-->
<!--#else -->
<!--#echo var="$DOCUMENT_NAME" -->
<!--#endif -->

I think it would be a smaller file if I could change the $DOCUMENT_NAME of "duh.html" to simply "duh" and if I could also then add to "duh" several additions at several points in the page to make it:

duhkeywords (to then include duhkeywords.txt)

duhtitle (to then include duhtitle.txt)

duhcontent1 (to then include duhcontent1.txt)

etc.

If I can get rid of the .html at the end of duh.html, then I can use DOCUMENT_NAME to eventually allow me to call these other files based on the prefix as added to by me rather than have all of these elif lines.

Any pointers on which topics in the apache 1.3 resources I should reread to learn to do this?

4thePegeh

3:43 pm on Mar 21, 2007 (gmt 0)

10+ Year Member



For clarification, I think I have learned how to add my desired additions (ex. "keywords", "title", "content1")to a variable such as what I expect "duh" will be.

What I am wondering is whether there is a way to change a DOCUMENT_NAME such as "duh.html" to "duh" without the ".html".

If so, any suggestions of which apache topics I should focus on would be appreciated.

If not, then also much appreciated would be letting me know that what I wish to do can't be done with apache alone.

[edited by: 4thePegeh at 3:45 pm (utc) on Mar. 21, 2007]

jdMorgan

4:05 pm on Mar 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From what I've found, it cannot be done with Apache mod_include (SSI) alone. You could of course use mod_rewrite to define a server variable with the file extension removed using RewriteRule's [E=value] facility, and then refer to that variable in SSI.

Alternately, you might consider using PHP instead of SSI, since PHP is much more powerful than the old and primitive SSI directives.

Jim

4thePegeh

6:20 pm on Mar 22, 2007 (gmt 0)

10+ Year Member



Thanks for the lead. I have looked into the rewrite option but from what I understand of it (which may be an incorrect understanding of it), I think I will go with the following in a single file to build what is necessary each time depending on what url is requested. This will be in a universal include file that is included from the file at the requested url:

<!--#set var="reqstdurl" value="$DOCUMENT_NAME" -->
<!--#if expr="$reqstdurl=unitest.html" -->
<!--#set var="inclprefix" value="unitest" -->
<!--#elif expr="$reqstdurl=testfixed3.html" -->
<!--#set var="inclprefix" value="testfixed3" -->
<!--#else -->
<!--#set var="inclprefix" value="unknown" -->
<!--#endif -->

I think I can avoid repeating all of the above at every step by doing it only once and then using:

<!--#include virtual="${inclprefix}meta.txt" -->

<!--#include virtual="${inclprefix}content1.txt" -->

<!--#include virtual="${inclprefix}content2.txt" -->

to insert particular files where needed.

Also, to prevent the if elif else endif statement from getting enormous, I could call any of several similar files so the alernatives are divided between them.

Not very elegant I suspect, but the above works when I test it, so I guess the syntax is correct.

Thanks again for taking the time to suggest the rewrite option.

[edited by: 4thePegeh at 6:27 pm (utc) on Mar. 22, 2007]

jdMorgan

10:25 pm on Mar 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or, in example.com/.htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.+)\.html$ - [E=inclprefix:$1]

and then on your pages:

<!--#if expr="(${inclprefix} != /^$/ && ${inclprefix} != /^(none)$/)" -->
<!--#include virtual="${inclprefix}meta.txt" -->
<!--#endif -->

Your choice... :)

Jim

4thePegeh

5:51 am on Mar 24, 2007 (gmt 0)

10+ Year Member



Thank you very much for posting examples of the necessary code.

My reading has, I think, allowed me to understand much of what is happening. I am new to metacharacters.

The additions to the .htaccess file seem to be having the desired effect because on a requested page I can successfully do these:

<!--#include virtual="${inclprefix}meta.txt" --> (when it is outside ofthe conditional statement)

and

<!--#echo var="inclprefix" -->

The example code is returning an error. My host runs Apache 1.3.37 (Unix)

I think I understand most of it, but I have not found clear explanations of:

/^$/

and of:

/^(none)$/

Does the first refer to inclprefix being without content because the two symbols mean the start and end of a line?

Does the second refer to a string automatically generated when?no matching url exists?

I have been looking at articles on metacharacters and conditional expressions but have not found meanings for the two above.

I understand the / to be for legibility and the ( and ) to group things.

I might have accidentally altered the syntax when I cut and pasted it so I will keep relooking at it.

[edited by: 4thePegeh at 5:58 am (utc) on Mar. 24, 2007]

4thePegeh

6:37 am on Mar 24, 2007 (gmt 0)

10+ Year Member



By process of elimination it seems to involve:

/^(none)$/

How it is involved I don't know.

I see echo prints (none) when I tell it to echo a variable that does not exist.

[edited by: 4thePegeh at 6:40 am (utc) on Mar. 24, 2007]

4thePegeh

7:27 am on Mar 24, 2007 (gmt 0)

10+ Year Member



This seems to work:

By adding \ before and after the brackets on (none) it seems to work

<!--#if expr="(${inclprefix}!= /^$/ && ${inclprefix}!= /^\(none\)$/)" -->

I think adding the \ escapes the ( and ) or changes them from meta to a literal characters.

Don't know whether adding the \ raises any other issues though.

I guess I will run with it.

Thanks again for the code example. It will make things much simpler.

[edited by: 4thePegeh at 7:29 am (utc) on Mar. 24, 2007]

jdMorgan

12:56 pm on Mar 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your solution to my error is correct, as were your assumptions about "(none)" being automatically generated. I forgot to escape the parentheses, which are in this case literals, and part of the auto-generated string.

The "^" and "$" are start and end anchors used in regular expressions. When combined as "^$", they match a blank string only. For more info about regular expressions, which are used in almost all modern scripting languages, see the regex tutorial cited in our forum charter [webmasterworld.com].

Jim

4thePegeh

6:56 am on Mar 26, 2007 (gmt 0)

10+ Year Member



Ok, Thanks again for your help.

I think that after working with the answers posted to all 10 of the threads I have started over the past 45 days, I am now in a position to implement this project.

Before I do I will head over and pay the subscription fee. The guidance received here at Webmaster World has, by warning me of unwise paths and offering guidance along wiser ones, saved me time worth more than the subsription price.

Thanks again!

[edited by: 4thePegeh at 6:56 am (utc) on Mar. 26, 2007]