Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- HTACCESS rewrite URL and remove Querystring


StupidScript - 9:31 pm on Jul 16, 2010 (gmt 0)


As a precursor to posting my own issues with Rewrite, let's break down the the RewriteRule in this thread:

RewriteRule ^(.*)\.html$ /scripts/gateway.php?action=SomeStaticAction&section=$1 [NC]


PATTERN:

^(.*)\.html$

^ = beginning of the string to test
(.*) = any number of any character(s) placed in a match container
\. = escape the period (checks for a period, not 'any character')
html = string 'html'
$ = end of the string to test


This seems to MATCH index.html, thing.html, etc.

This is the PATTERN to seek, yes? Any number of any character(s) at the beginning of the test string followed by a period and the string 'html'.

Then the SUBSTITUTION:

/scripts/gateway.php?action=SomeStaticAction&section=$1 [NC]

/scripts/gateway.php?action=SomStaticAction&section= = INCLUDE this string
$1 = referencing the contents of the first match container in the PATTERN ((.*))
[NC] = case-insensitive


Seems to say: "Take whatever is in the matching container in the PATTERN and include it at the end of the SUBSTITUTION string."

So the result should be:

PATTERN MATCHED:
index.html

SUBSTITUTION TO PERFORM:
/scripts/gateway.php?action=SomeStaticAction&section=index

I am bringing this up because this thread and a few others around town seem to be indicating that the PATTERN to be matched is

/scripts/gateway.php?action=SomeStaticAction&section=$1 [NC]

and the SUBSTITUTION is

^(.*)\.html

"..to create nice URLs like example.com/SomeStaticAction.html"

I see that in subsequent messages, the OP seems to be sending everything into the /scripts/ directory and then rewriting everything back to get a "clean" URI with the second set of instructions, but in the first message it seems like the posted code would NOT result in a "clean" URI. Maybe that was a mistake? Maybe the first post should have ALSO included the second set of instructions? Otherwise, how could the OP have obtained "clean" URIs with what was posted?

I just don't get it.

What is in the "address bar" area before the rewrite?
What is in the "address bar" area after the rewrite?

Can someone please clarify the relationship between PATTERN and SUBSTITUTION? It seems exactly backwards in the first part of this thread, and unaddressed after that.

Thanks.


Thread source:: http://www.webmasterworld.com/apache/4171357.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com