Subdomain to Subdirectory Rewrite

Hello,

Looking for some more help with rewrite rules, here’s the older structure:

subdomain.example.com/YYYYMMDD-title-permalink-slug/

New structure:

http://www.example.com/subdomain/YYYY/MM/DD/title-permalink-slug/

Thanks,
Grant

Grant,

What’s so hard about that? It’s trivial to cut up a date string like that!

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\\.example\\.com$
RewriteCond %{HTTP_HOST} ^([a-z]+)\\.example\\.com$
RewriteRule ^(\\d{4})(\\d{2})(\\d{2})-([a-z]+)-([a-z]+)-([a-z]+)/ http://www.example.com/%1/$1/$2/$3/$4-$5-$6/ [R=301,L]
# note, with lack of definition, I've assUmed title, permalink and slug were strictly lowercase letters

You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.

Regards,

DK

What if I don’t know what the permalink will be? Could be 3 words, could be 12?

Thanks,
Grant

PS - I’ll definitely check out your mod-rewrite article once I get this project complete. Always seem to be running into them. Thanks

Grant,

If you use multiple words in your “permalink” example, then you must account for the words by changing the spaces (or suffering the %20 which browsers and servers will use instead of a space character). I provide the arguement in my tutorial for changing to _'s rather than the more common -'s because hyphens are commonly found in text whereas _'s are not and changing them back before accessing your database (I’ve even provided sample PHP code for each). Also, UPPERCASE letters should be accounted for, too. An example of this (with some punctuation characters, too) is used in the navigation at [noparse]http://wilderness-wally.com[/noparse].

Regards,

DK