Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule seems tricky?

Well it seems more tricky then it proberly is.

         

matc

9:52 pm on Dec 1, 2004 (gmt 0)

10+ Year Member



Hello all,

Got a problem that needs some advice. I have a number of files where both the target file name and path are going to be changed.

There are two types of file names in the directory before the change:
*1 /main/includes/ski/france_place_name.shtml [- with underscore.]
*2 /main/includes/ski/france_placename.shtml [- without underscore.]

And heres the **ideal** URI structure after the change:
/main/show/ski/index.shtml?resort=placename [- no trace of a underscore >:->.]

Hopefully you can see the problem.

So far I have had no problem in redirecting either one or the other file name types at any one time but not a handle for both, not very nicely anyway. Even when I used '¦' pipe delimiter to define the two types it seems hard to me, at this late hour, on how to actually get rid of the underscore in the first file type e.g. pleace_name.shtml.

I should proberly give myself a slap and get book swating on RegEx again but in the meantime can anyone offer some advice on this problem.

Many Thanks, mat

dcrombie

2:33 pm on Dec 2, 2004 (gmt 0)



Something like this (untested)?

RewriteRule ^main/includes/ski/france_([^_]+)_?([^_]*)\.shtml /main/show/ski/index.html?resort=$1$2

;)

matc

3:10 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



Cool and thanks dcrombie for the shout on this, I had a better look and came down to this below but thanks again.

RewriteRule ^[a-z]+_([a-z]+)\.shtml$http://www.website.co.uk/main/show/ski/index.shtml?resort=$1[R=301,L]
RewriteRule ^[a-z]+_([a-z]+)_([a-z]+)\.shtml$ [website.co.uk...]
RewriteRule ^[a-z]+_([a-z]+)_([a-z]+)_([a-z]+)\.shtml$ [website.co.uk...]
RewriteRule ^[a-z]+_([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)\.shtml$ [website.co.uk...]
RewriteRule ^[a-z]+_([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)\.shtml$ [website.co.uk...]

cheers, mat

jdMorgan

9:06 pm on Dec 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A question...

Why do you want those dynamic URLs to show in the user's address bar and in search engine listings? This "cancels" the value of converting your links to static-looking URLs.

Changing your first rule as an example of how to do this with a "silent" internal rewrite, we get:


RewriteRule ^[a-z]+_([a-z]+)\.shtml$ /main/show/ski/index.shtml?resort=$1 [L]

Note that the missing spaces (corrected here) are required.

Jim

matc

2:23 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



Hi jdMorgan,

> A question...

A good question.

I suppose its habbit, I coded the RewriteRule to clear up on a recent change I made to a site. This rule can only be live for a month and then I have to remove it. I wanted the user and Search Engine to get a jump on the fact that requests to the first page has since been moved and has been moved permanently.

Cheers for the shout on the spaces as well I always forgetting about that... getting a bit too tab happy :)

Cheers, mat