Forum Moderators: phranque

Message Too Old, No Replies

slash in begining of rewrite rule give problem

A windows issue!?

         

leatherback

11:35 am on Aug 31, 2005 (gmt 0)

10+ Year Member



Hi All,
I have a bit of a problem with including a slash in the begining of a regexp for mod.rewrite.

Why is it that this:

RewriteRule [pics/]([^/]+)/([^/]+)/$ pics.php\?$1=$2 [L]

works, and this not:

RewriteRule pics/([^/]+)/([^/]+)/$ pics.php\?$1=$2 [L]

when calling this url: ..website/portfolio/pics/c/australia/

But this does:

RewriteRule pics([^/]+)/([^/]+)/$ pics.php\?$1=$2 [L]

when calling: website/portfolio/picsc/australia/

(I finally effectively want the page:
website/portfolio/pics.php?c=australia to load, and am running apache 1.3 on win 2000 pro)

Thanks,

jelle.

jdMorgan

2:15 pm on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For clarity, please confirm that the following URL in your post is typed correctly:

website/portfolio/picsc/australia/

That is, "pics/" in the pattern will not match "picsc/" in the request.

Jim

leatherback

6:31 pm on Sep 1, 2005 (gmt 0)

10+ Year Member



Hi Jim,

you are right, there was a typo in the post. Obviously, I did type the right link in the browser (And I rechecked just now ;-) )

J.

jdMorgan

7:43 pm on Sep 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Missing slash afters "pics":

RewriteRule pics[b]/[/b]([^/]+)/([^/]+)/?$ pics.php\?$1=$2 [L]

Added the "?" to make the trailing slash optional. Omit it if you like.

Jim

leatherback

7:53 pm on Sep 1, 2005 (gmt 0)

10+ Year Member



Hi Jim,

Actually, no. That was the whole issue.

It will NOT match

RewriteRule pics/([^/]+)/([^/]+)/$ pics.php\?$1=$2 [L].

Somehow, the slash after pics is throwing the matrching off. therefore I did try without the / after pics, and in the url, to check it was the first slash.

so:

RewriteRule [pics/]([^/]+)/([^/]+)/$ pics.php\?$1=$2 [L]
url: ..website/portfolio/pics/c/australia/
works,

RewriteRule pics([^/]+)/([^/]+)/$ pics.php\?$1=$2 [L]
url: ..website/portfolio/picsc/australia/
works [if I do not use the slash in the url], and this:

RewriteRule pics/([^/]+)/([^/]+)/$ pics.php\?$1=$2 [L]; ..website/portfolio/pics/c/australia/

does not give a match.

jdMorgan

4:18 am on Sep 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What directory is this code in?

The pattern "[pics/]" means, "match any single character equal to p, i, c, s, or /", so this behaviour is very strange.

Jim

leatherback

7:03 am on Sep 2, 2005 (gmt 0)

10+ Year Member



The actual folder is ..website/portfolio/
This is also where the .htaccess file is located

In it, is a file called pics.php, which takes a number of variables, which I am trying to rewrite from statics URL to $_GET querystring for the script. I must say, I was stumped to find out that the first slash, when not placed within valid chars brackets [] stops the matching.
I would have thought that

RewriteRule pics/([^/]+)/([^/]+)/$ pics.php\?$1=$2 [L]
would give a match when calling this url:..website/portfolio/pics/c/australia/

Any ideas on the why and how of this, would be highly appreciated. (It really is not easy learning how to do this stuff if your server appearently doesn't linke the characters which other people seem to be using..)

Thanks for your ideas & help

Jelle.

jdMorgan

10:16 pm on Sep 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, this is abnormal, and I've no idea what could be causing the problem.

All I can offer is code snippets which should work properly if everything is set up correctly. I'm not sure what part of your posted URLs are shorthand, and what part is literal, so...

If the .htaccess file in is http://example.com/portfolio/:


RewriteRule ^pics/([^/]+)/([^/]+)/$ /portfolio/pics.php?$1=$2 [L]

Or if the .htaccess file in is http://example.com/website/portfolio/:

RewriteRule ^pics/([^/]+)/([^/]+)/$ /website/portfolio/pics.php?$1=$2 [L]

One of those should work, if I got the local URL-path of your .htaccess file right.

Best advice is to keep the tests simple; Try a simple test in the Web root folder (home page folder) of your server. If that works, try a similar test one subdirectory down. Keep going until you get to /portfolio/pics/. Then try a more complex rewrite, like the ones above, starting again at the top directory.

Somewhere in the process you may hit an unexpected situation that gives a clue as to where the porblem may be.

Oh, by "simple" I mean:


RewriteRule ^foo\.html$ /bar.html [L]

or some such similarly-trivial rule. In order to aid debugging, you can also change it to the external redirect form, so the rewrites will 'show' in your browser:

RewriteRule ^foo\.html$ http://www.example.com/bar.html [R=301,L]

Flush your browser cache after changing any code in .htaccess, and... Good luck with this!

Jim

leatherback

12:14 pm on Sep 3, 2005 (gmt 0)

10+ Year Member



Hi Jim,

THanks for your reply. I guess I'll start playing, and trying then. I was hoping somebody would ge up and say "Yeah, but you cannot do that under windows! There you need to do.. ". But I guess it is a strange thingyg in my server. I'll see how to deal with this. Probably have a different .htaccess on my test server then on my live server (Where all codes give the expected result).

Thanks again,

Jelle.

jdMorgan

3:39 pm on Sep 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, it could be a problem with the POSIX regular-expressions library on your version of Windows, or you might have an old or corrupted copy of mod_rewrite. I'm just guessing here, and would have no idea what to do about it other than re-install/upgrade Apache and the OS, which, due to the inevitable problems, I really can't recommend.

Jim