Forum Moderators: phranque

Message Too Old, No Replies

Permanent 301 using parameters

         

Nimisha

2:58 am on Mar 4, 2008 (gmt 0)

10+ Year Member



Hi All

I've been reading many posts on this but can't quite work out the regular expression. I am migrating my site to Joomla 1.5 and their SEF urls are not the same as my current site (Joomla 1.0) but the parameters will work

ie:

domain.com/content/view/2161/30/

will work as:

domain.com/jokes/30/2161

Is there a rewrite rule I can use for this?

jdMorgan

6:11 pm on Mar 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, I'm sure there is, but it's not clear which is the "old" URL and which is the new, and whether they need to be rewritten to a filepath.

It would be helpful to make this clear by doing something like this:

example.com/content/view/<item-number:digits-only>/<category:digits-only>/ --rewrite to--> /jokes/<categoty>/<item-number>

domain.com/content/view/<item-number:digits-only>/<category:digits-only>/ --rewrite to--> /script.php/cat=<category>&item=<item-number>

to show what is fixed, what is a variable, how the variables are ordered in both the input and output, what kind of characters are acceptable in each variable, and what the destination path should be.

Also, you should say if you want to simply deliver content from the new path when the old URL is requested, or instead to redirect requests for the old path to the new path, so that search engines will update their databases to use the new URL(s).

Jim

Nimisha

12:00 am on Mar 5, 2008 (gmt 0)

10+ Year Member



I didn't realize and I"m sorry if I was unclear.. I did work that particular solution out though:

RewriteRule ^content/view/([0-9]+)/([0-9]+)/?$ /jokes/$2/$1/ [L,R=302]

I am stuck on another one. My Rule (that does not work)

RewriteRule ^component/option,com_rsgallery2/Itemid,45/page,inline/id,([0-9])/catid,([0-9])/limitstart,0/?$ /index.php?page=inline&id=$1 [L,R=302]

Using this rule its not redirecting. The Old URL that I'm trying to match is

component/option,com_rsgallery2/Itemid,45/page,inline/id,971/catid,15/limitstart,0/

I hope thats more defined.

g1smd

12:57 am on Mar 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What is the reason for choosing a 302 redirect rather than a 301 redirect in your first example?

In your second example, are you sure you need a redirect? Isn't it a rewrite that you really need?

Nimisha

3:48 am on Mar 5, 2008 (gmt 0)

10+ Year Member



I am usung 302 at the moment whuile I am testing and debugging. I didn't want to do any permanent redirects until I am sure they are working properly. The site is still in development.

Not sure what you mean in the second comment? I am doing a RewriteRule ... /shrug lost now

jdMorgan

6:13 am on Mar 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you're needing in your rule pattern is a quantifier. The pattern [0-9] matches a single character in the range of 0 to 9 inclusive. If you want to match more, then you need a quantifier.

Regular-expressions quantifers are:
? -- Zero or one of the preceding characters
* -- Zero or more of the preceding characters
+ -- One or more of the preceding characters
{n} -- n characters. Example: {3} "Three of the preceding characters"
{min,max} - any quantity between and including min and max. Example: {2,5} "from 2 to five of the preceding characters"
{min,} -- Any quantity including or above min. Example: {2,} "two or more of the preceding characters"
{,max} -- Any quantity including or below max. Example: {,9} "zero to nine of the preceding characters"

So in your case, you might use ([0-9]{2}) for the first numeric subpattern and ([0-9]{3}) for the second, if you're always looking to match 2-digit catIDs and 3-digit ItemIDs. Or you could specify an acceptable range, such as ([0-9]{1,4}) for both of them, or just accept any number of digits, by using ([0-9]+).

Jim

Nimisha

6:25 am on Mar 5, 2008 (gmt 0)

10+ Year Member



Doh I missed the + now I feel blonde

Thank you :) It is a range.

jdMorgan

7:10 am on Mar 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh, you should see some of my "D'Oh!s" -- They're not pretty... :)

Jim