Rewrite rule regex help

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
mo
Posts: 306
Joined: Tue Mar 11, 2003 1:40 am

Rewrite rule regex help

Post by mo »

Hello,

A friend needs the following help which I hope someone here can give:

# I can't figure out how to get RewriteRule to work so that we can put
# anchors in the URLs. Here's what I've tried:
# RewriteEngine on
# RewriteRule ^(.*) $1 [ NE]
#
# I'd really like this to work so that the old anchored URLs can be properly
# redirected:
# Redirect permanent /canon/sutta/khuddaka/theragatha/thag14.html#1 http://www.accesstoinsight.org/canon/su ... 1-tb0.html
# Redirect permanent /canon/sutta/khuddaka/theragatha/thag14.html#2 http://www.accesstoinsight.org/canon/su ... 2-tb0.html
# Redirect permanent /canon/sutta/khuddaka/therigatha/thig05.html#2 http://www.accesstoinsight.org/canon/su ... 2-tb0.html
Best Wishes!
Mike Olds
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

I don't think it is possible.

The fragment identifiers (what you call anchors) are not part of the URL. Therefore they are not transmitted in the request, and therefore your rewrite rules will not match.

If you look at the request that is sent e.g. for http://localhost/test.html#123, you should see something like

Code: Select all

GET /test.html HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8) Gecko/20051111 Firefox/1.5
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Note the absence of the fragment identifier ...

A fragment identifier only idenitifies a fragment of a resource - HTTP doesn't support the transport of resource fragments - therefore it doesn't make any sense to send the fragment identifier in the request, the whole resource has to be sent by the server anyway.
mo
Posts: 306
Joined: Tue Mar 11, 2003 1:40 am

Post by mo »

Thanks MudGuard.
Best Wishes!
Mike Olds
Post Reply