Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

htaccess redirect old to new url with different directories but same filename without extension

8 views
Skip to first unread message

webonomic

unread,
Apr 17, 2012, 11:39:55 PM4/17/12
to
This may not be the correct group to ask for help on htaccess, but
I've searched high and low for answers and I don't know where else to
turn.
I almost have a working solution. Current code is this:

Options +FollowSymLinks
RewriteEngine on
RedirectMatch permanent (.*).html$ http://newdomain.com/blog/$1/
[R=301,L]

The problem with the above code is that it retains the directory
structure. I moved my blog from olddomain.com for which a typical URL
is:
http://olddomain.com/2012/01/17/some-file-here.html

The new domain is as such:
http://newdomain.com/blog/some-file-here/

So the new domain does not have the same folder structure but has the
same filename minus the file extension. I have hundreds of HTML files
that are now in this new URL format, so one rule is preferable. Can
someone explain how I can correct the htaccess code?

TIA,
Jared

Jim

unread,
Apr 18, 2012, 11:31:47 PM4/18/12
to
Well, if the some-file-here is the same for both old and new urls and
you just dropped that year,month, day, this might work:

RewriteRule ([0-9]+/[0-9]+/[0-9]+/(.*).html
http://newdomain.com/blog/$1/ [R=301,L]

You could check for 4 digits/2 digits/2 digits by adding the count to
the pattern.

Note that I used RewriteRule because I am more familiar with that than
RedirectMatch.

Jim
0 new messages