Discussion:
htaccess redirect old to new url with different directories but same filename without extension
(too old to reply)
webonomic
2012-04-18 03:39:55 UTC
Permalink
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
2012-04-19 03:31:47 UTC
Permalink
On Tue, 17 Apr 2012 20:39:55 -0700 (PDT), in alt.apache.configuration,
Post by webonomic
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.
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
http://olddomain.com/2012/01/17/some-file-here.html
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
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

Continue reading on narkive:
Search results for 'htaccess redirect old to new url with different directories but same filename without extension' (Questions and Answers)
5
replies
Can someone running php,mysql and apache, paste their httpd.conf file because mine is giving errors.Thanks?
started 2007-06-03 13:02:46 UTC
programming & design
Loading...