Mod Rewrite - Just can't get it right

Hi

I have spend the last couple of days scouring the internet but I can’t figure out how to do this.

Basically I need the page…

www.domain.com/page1/12345678

to redirect to

www.domain.com/page2/page1/12345678

I thought I might be able to do it with mod_alias but I end up in an infinite loop.

What I have so far is

RewriteCond %{QUERY_STRING} ^(.*&)/page1/([0-9]+)?$ [NC]
RewriteRule ^/page1/([0-9]+)?$ /page2/page1/$2 [R=301,L]

but I’m just not hitting the rule.

I have spend hours on this and I just can’t work out what I am doing wrong.

Any help would be very much appreciated.

Thanks

Si

mod_alias should be able to do that just fine. Try this:


Redirect permanent /page1/12345678 http://www.example.com/page2/page1/12345678 

(where of course [noparse]www.example.com[/noparse] has to replaced with your real domain)

Sorry, I wasn’t very clear.

The last part, 12345678, is dynamic.

What I tried with mod_alias was

RedirectMatch ^/page1/([0-9]+) http://www.example.co.uk/page2/page1/$1

This works where redirecting from 1 domain to a seperate domain, but when using the same domain it seems to cause a loop.

I tried your suggestion but it won’t let me use any expressions in this.

Thanks

Si

S&M,

Rémon’s suggestion is a good one - for fixed content. However, with 12345678 being dynamic, leave it off the end of the “from” and “to” code as mod_alias will redirect the directories and leave the “file” request alone.

I believe that’s the reason that your RewriteMatch isn’t working - although it should work properly.

As for your mod_rewrite code:

[COLOR="Red"]RewriteCond %{QUERY_STRING} ^(.*&)/page1/([0-9]+)?$ [NC][/COLOR]
# Are you trying to redirect FROM the query string version to the non-servable version?
# If so, have a read of the "Loopy" section of my tutorial Article
RewriteRule ^/[COLOR="Blue"]?[/COLOR]page1/([0-9]+)?$ /page2/page1/$2 [R=301,L] 

I’m bothered by the fact that you’re not telling us what you’re REALLY trying to do, i.e., SPECIFICITY! With digits in the place of a file, what are you serving? Quite obviously, you’re not giving us the whole picture so we really can’t be of much help (except on troublesome points).

Regards,

DK

Hi

Apologies for being a bit vague.

Basically we are releasing a new website. The developers in their wisdom have decided to change the URL structure.

So what I am trying to do is preserve any inbound links once the website is changed over.

As for the digits in place of a file, the site is built on a framework, and those numbers are stock IDs. They are not actual files.

Had a bit more of a play about, and I seem to have got it working by using your mod_alias suggestion.

Thanks a lot for your help guys.

Si