homepage Welcome to WebmasterWorld Guest from 54.205.247.203
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

    
RewriteRule problem
Need to remove some text AND change file ext
cookie2




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

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.

 

lucy24




msg:4671764
 7:22 pm on May 16, 2014 (gmt 0)

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?

cookie2




msg:4671767
 7:47 pm on May 16, 2014 (gmt 0)

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.

g1smd




msg:4674274
 7:40 pm on May 24, 2014 (gmt 0)

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.

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