Active TopicsActive Topics  Display List of Forum MembersMemberlist  HelpHelp   RegisterRegister  LoginLogin
ISAPI_Rewrite 2.x support forum
 Helicon Tech : ISAPI_Rewrite 2.x support forum
Subject Topic: Trailing slash pattern Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Kevin Collins
Groupie
Groupie


Joined: 08 April 2003
Location: United States
Online Status: Offline
Posts: 64
Posted: 13 January 2005 at 8:13pm | IP Logged Quote Kevin Collins

I've seen this rule posted here, which redirects requests for directories that do not end with a slash.

RewriteCond Host: (.*)
RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [I,R]

I don't understand how the RewriteRule pattern works. Yaroslav, Lexey, or anybody else would you please walk me through it?

([^.?]+[^.?/])

My attempt at interpretation:

[^.?] means "Anything except (any single character (zero or one time only))."

Sorry not making sense. I understand you can match either a single character one time or a single character zero times. But what matches anything except that (signified by the caret)?

+ means "The preceding expression repeated one or more times."
[^.?/] means "Followed by anything except (any single character (zero or one time only) or a slash)."

Also I was glad to see the pattern doesn't match requests ending in file names, so for example you don't get redirected to /index.html/ when you request /index.html. However I would like to understand how this works.

Thanks,
Kevin

Back to Top View Kevin Collins's Profile Search for other posts by Kevin Collins
 
Lexey
Moderator Group
Moderator Group


Joined: 15 August 2002
Location: Russian Federation
Online Status: Offline
Posts: 7955
Posted: 14 January 2005 at 4:27am | IP Logged Quote Lexey

>My attempt at interpretation:

>[^.?] means "Anything except (any single character (zero or one time only))."

:) Inside a set '?' and '.' are normal characters. So that means any character except '?' or '.'.

>+ means "The preceding expression repeated one or more times."

>[^.?/] means "Followed by anything except (any single character (zero or one time only) or a slash)."

That means "followed by anything except '?', '.' or '/'.



__________________
With best wishes,
Alex Ostapenko,
Helicon Tech.
Back to Top View Lexey's Profile Search for other posts by Lexey
 
Kevin Collins
Groupie
Groupie


Joined: 08 April 2003
Location: United States
Online Status: Offline
Posts: 64
Posted: 15 January 2005 at 9:35pm | IP Logged Quote Kevin Collins

>Inside a set '?' and '.' are normal characters.
Thanks very much for clearing that up!

Is it possible for this to work when just the hostname is requested? For example, redirect http://www.example.com to http://www.example.com/
I'm not sure it's possible because even when you don't type the trailing slash in the browser it appears in the actual HTTP request.

Thanks

Back to Top View Kevin Collins's Profile Search for other posts by Kevin Collins
 
Lexey
Moderator Group
Moderator Group


Joined: 15 August 2002
Location: Russian Federation
Online Status: Offline
Posts: 7955
Posted: 17 January 2005 at 5:19am | IP Logged Quote Lexey

No, that is not possible. Browser will request '/' from server even if slash was omitted in an adress bar.

__________________
With best wishes,
Alex Ostapenko,
Helicon Tech.
Back to Top View Lexey's Profile Search for other posts by Lexey
 
Yaroslav
Moderator Group
Moderator Group


Joined: 15 August 2002
Online Status: Offline
Posts: 6470
Posted: 17 January 2005 at 5:22am | IP Logged Quote Yaroslav

That's why it is useless. There cannot be a http://www.example.com request in the HTTP specification. When you enter http://www.example.com in the address your browser will automatically translate it to the http://www.example.com/ and you don't need to rewrite it serverside.

__________________
Yaroslav Govorunov,
Helicon Tech
Back to Top View Yaroslav's Profile Search for other posts by Yaroslav Visit Yaroslav's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum