Forum Moderators: phranque

Message Too Old, No Replies

Rewrite from multiple files to single file on vhost

         

TxJack

12:38 am on Aug 29, 2007 (gmt 0)

10+ Year Member



This is my first post and hope I do it right.

Am running Apache-2.0+ on FBSD-6.2px

I do all rewrites in the httpd.conf

Problem is that I have 10-12 existing files named like:
cdrom1.htm
cdrom2.htm
.........
cdrom12.htm

I need to redirect all of the above requests for the existing files to only cdrom.htm

Reading some other redirects, I took several shots at it over the past hour or so and nothing works so far. So, how would I do this?

RewriteEngine On
redirect from: http://www.example.com/folder/cdrom[0-9]+.htm$
to: http://www.example.com/folder/cdrom.htm$

BTW: Have not used the above lines, but just explains what I'm trying to do.

Thanks for any tips!

Really enjoying the forums.

TxJack

[edited by: jdMorgan at 1:18 am (utc) on Aug. 29, 2007]
[edit reason] example.com [/edit]

Receptional Andy

1:37 pm on Aug 29, 2007 (gmt 0)



Hi TxJack, welcome to webmasterworld [webmasterworld.com] :)

You are nearly spot on with your rule. You don't need to use the $ symbol to specify the end of the string in the URL to redirect to. A (hopefully!) working rule is below:

RewriteRule ^folder/cdrom[0-9]+.htm$ /folder/cdrom.htm [R=301,L]

jdMorgan

2:17 pm on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I do all rewrites in the httpd.conf

So you'll need a leading slash:


RewriteRule [b]^/f[/b]older/cdrom[0-9]+[b]\.h[/b]tm$ http://www.example.com/folder/cdrom.htm [R=301,L]

Also, escape the literal period in the pattern as shown, and use a canonical substitution URL in case UseCanonicalName is enabled, and your host has defined a different canonical domain from what you prefer -- It's cheap insurance.

Jim

TxJack

11:04 pm on Aug 29, 2007 (gmt 0)

10+ Year Member



JD

Your syntax works like a charm!

Many thanks to all.

TxJack

PS: Apology for whatever I did wrong on this first post.

g1smd

6:32 pm on Sep 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Glad it worked. Forum rules say to use example.com instead of the real domain. It just discourages people "link dropping" in posts. Where people forget to do that, the moderators just edit the post to comply. Goog luck with your site!

jdMorgan

7:04 pm on Sep 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It also prevents WebmasterWorld from replacing your site as the top result for a search on your domain... :)

Jim