homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

301 Redirect File Series URLs
How to set up a redirect rule to redirect a series of file names

 11:21 am on Jan 11, 2009 (gmt 0)


I have some file names such as



and so on...

Though I can set up 301 redirects for individual file names such as

redirect 301 /filename1.html http://www.example.com/

redirect 301 /filename2.html http://www.example.com/

I was wondering if there can be a rule set that would redirect all the series of files from /filename1.html to /filename9.html at one go to the root domain.

I tried this one, but doesn't work:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^/filename([0-9])\.html http://www.example.com/ [R=301,L]

Thanks in advance!



 12:22 pm on Jan 11, 2009 (gmt 0)

It definitely is doable, so don't give up, and you should be very close to the solution. I'm not sure if this is the only modification needed. I removed the forward slash before filename:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^filename([0-9])\.html http://www.example.com/ [R=301,L]


 12:35 pm on Jan 11, 2009 (gmt 0)

OMG! Thanks a ton Steve :-)

It is working by just removing the forward slash before the filename.

Thanks again!


 3:05 pm on Jan 11, 2009 (gmt 0)

You'd better try something different because your rule will redirect all files to the root index file. The following looks better to me :)

RewriteRule ^(filename[0-9]+\.html)$ http://www.example.com/$1 [R=301,L]

PS: Just didn't notice this was exactly your intent to 301 redirect all to the root index. So, your rule would be okay.


 5:35 pm on Jan 11, 2009 (gmt 0)

Notice the
+ in that final example.

It allows the number to be more than one digit if required.

The ( ) are not needed, and neither is the $1 part.


 7:26 am on Jan 12, 2009 (gmt 0)

Thanks a lot for your replies guys.

The code worked just be removing the forward slash and g1smd, I have noted down your suggestions as well.

Thanks again :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved