Welcome to WebmasterWorld Guest from 107.22.87.205

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

RewriteRule problem

Need to remove some text AND change file ext

     
3:16 pm on May 16, 2014 (gmt 0)

10+ Year Member



Regular expressions and I aren't friends. ;)

I need to redirect a file request using htaccess. The file being requested is:

http://example.com/blogs/myblog/2014/05/ready_130_tourist_in_the_wild.htm

I need to remove the "ready_130_" (numbers will vary) as well as change the file extension from .htm to .html

I've tried several incarnations of things, most recently this but it throws a 500 server error and I'm stuck now:

RewriteRule (blogs/myblog/)(\d{0,4}/)(\d{0,2}/)ready_[0-9][0-9][0-9]_(.*) http://example.com/$1$2$3$4l [R=301,L]



Any help offered would be appreciated. Thanks.
7:22 pm on May 16, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Why are there four captures when all you need to retain is before and after? I'm looking at

RewriteRule ^(blogs/myblog/\d+/\d+/)ready_\d+_([^.]+)\.htm http://example.com/$1$2.html [R=301,L]


That's assuming you have other RewriteRules so the
RewriteEngine on
directive is already present. But its absence wouldn't lead to a 500 error; it just prevents the rule from executing.

It's safer to simply omit the whole extension from the capture, and reappend a new one. You don't ever have literal periods in your filenames do you?
7:47 pm on May 16, 2014 (gmt 0)

10+ Year Member



Yes, ReWrite Engine is on for others. I tried to do it in 4 captures because I didn't know I could do it in less. And I wasn't aware of a way to omit file extension and reappend a new one.

Looking at what you did makes sense when I see it but when I try to come up with a way to do it in my head, it's like I blank out and try to figure how to do each capture instead of one or two for everything.

Thank you for your help, lucy.
7:40 pm on May 24, 2014 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Capture the bits for re-use that you need to. Bracketing is numbered lest to right.

Don't capture the bits that will be changed or discarded. Once you have done it a few times it becomes easier.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month