views:

48

answers:

1

[UPDATE]

What I ask below just isn't possible. In which case, as my brain hurts, how can I simply redirect

mydomain/folderA/folderB/name-0000.php

to

myNewDomain/folderC/folderB/name.php

[/UPDATE]

I currently have some URL's which follow the pattern below.

/folder/folder2/name-name-id.php

The content has now been moved to a new domain with a different file structure. Redirecting them would be simple enough to do if it weren't for the fact that the ID portion of the URL is now different.

So I need to be able to redirect the following from domain A:

/folderA/folderA2/name-name-0000.php

to this on domain B:

/folderB/folderB2/name-name-5555.php

I can't figure out how to match the name portion and ignore the id. Note, the name could be n number of words long, it's not limited to two.

Any ideas?

A: 

Try this regular expression for the URL path:

^/[^/]+/[^/]+/[^/]+-[0-9]+\.php$

Now your mod_rewrite rule for the .htaccess file in your root directory can look like this to match the name and ID:

RewriteRule ^folderA/folderA2/([^/]+)-([0-9]+)\.php$ …


Edit    After you edited your requirements:

RewriteRule ^folderA/([^/]+)/([^/]+)-[0-9]+\.php$ /folderC/$1/$2.php [L,R=301]
Gumbo
Thanks, but I don't think its possible without knowing the new ID.
Ben
Yes, works perfectly, thanks for the help and quick response.
Ben