Welcome to WebmasterWorld Guest from 54.162.184.214

Forum Moderators: Ocean10000 & incrediBILL & phranque

RewriteRule

     
12:48 pm on Jan 30, 2018 (gmt 0)

New User

joined:Jan 30, 2018
posts: 6
votes: 0


hello
i try to do this

capture this type of url

http:// www.domain.com/image.axd?picture=%2fYYYY%2fMM%2fimagefilename.jpg

and transform in url like this

https:// www.domain.com/folder/subfolder/YYYY/MM/imagefilename.jpg

where YYYY are 4 numbers stand for year
where MM are 2 number and stand for mounth

some advice?
thank you
3:10 pm on Jan 30, 2018 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11279
votes: 133


hello
i try to do this

welcome to WebmasterWorld [webmasterworld.com], iamin!

what have you tried so far?
3:52 pm on Jan 30, 2018 (gmt 0)

New User

joined:Jan 30, 2018
posts: 6
votes: 0


RewriteRule ^(.*).axd?picture=$ https://www.domain.com/$1/ [R=301,L]
RewriteRule /\d{4}/\d{2}/(.*) /$1/ [R=301,L]

[edited by: phranque at 3:58 pm (utc) on Jan 30, 2018]
[edit reason] Unlinked URL for clarity [/edit]

7:07 pm on Jan 30, 2018 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:14709
votes: 613


A RewriteRule only sees the URL path; it doesn't see the query string. The query has to be captured in a RewriteCond.
12:02 pm on Jan 31, 2018 (gmt 0)

New User

joined:Jan 30, 2018
posts: 6
votes: 0


Thanks Lucy24,
can i hire someone to fix the problem?
thanks
2:45 pm on Jan 31, 2018 (gmt 0)

New User

joined:Jan 30, 2018
posts: 6
votes: 0


now i try this

RewriteCond %{QUERY_STRING} ^picture=(.*)$ [NC]
RewriteRule ^(.*).axd$ https://www.example.com/wp-content/uploads/upload/%1? [R=301,L]

url
https: //www.example.com/image.axd?picture=%2f2013%2f02%2fimg.jpg

result
https: //www.example.com/uploads/upload/%252f2013%252f02%252fimg.jpg

how can i transform %252f char in /
to obtain

https: //www.example.com/uploads/upload/2013/02/img.jpg
thanks
4:30 pm on Jan 31, 2018 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11279
votes: 133


you'll need an internal rewrite loop to incrementally fix the percent-encoded characters one at a time.

this thread might give you some hints:
Rewriting URLs containing percent-encoded characters [webmasterworld.com]
6:30 pm on Jan 31, 2018 (gmt 0)

New User

joined:Jan 30, 2018
posts: 6
votes: 0


Thank you phranque
this overcome my possibility is possible hire someone to solve the question?
9:15 pm on Jan 31, 2018 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:14709
votes: 613


how can i transform %252f char
I'd worry about how you arrived at %25blahblah in the first place, since that's double encoding (the % sign by itself is %25). One option is to rewrite to a php script that does the decoding and wraps up by issuing the redirect, as in:

RewriteRule ^image\.axd /fixup.php [L]
(conditionless, I think). It shouldn't be necessary to capture anything, since the php page can still "see" the originally requested URL, query and all. Note that although this is superficially a rewrite ([L] flag alone), the rule needs to be placed among the redirects in htaccess, because this hypothetical php page will wind up by issuing a redirect; the request will never see your htaccess again.

:: wandering off to look up what on earth .axd is ::
8:01 pm on Feb 1, 2018 (gmt 0)

New User

joined:Jan 30, 2018
posts: 6
votes: 0


Thank you lucy24

i will try your suggested way


:: wandering off to look up what on earth .axd is ::
Yes i made the same thought when i see it