Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule

         

iamin

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

5+ Year Member



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

phranque

3:10 pm on Jan 30, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



hello
i try to do this

welcome to WebmasterWorld [webmasterworld.com], iamin!

what have you tried so far?

iamin

3:52 pm on Jan 30, 2018 (gmt 0)

5+ Year Member



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]

lucy24

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

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



A RewriteRule only sees the URL path; it doesn't see the query string. The query has to be captured in a RewriteCond.

iamin

12:02 pm on Jan 31, 2018 (gmt 0)

5+ Year Member



Thanks Lucy24,
can i hire someone to fix the problem?
thanks

iamin

2:45 pm on Jan 31, 2018 (gmt 0)

5+ Year Member



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

phranque

4:30 pm on Jan 31, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



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]

iamin

6:30 pm on Jan 31, 2018 (gmt 0)

5+ Year Member



Thank you phranque
this overcome my possibility is possible hire someone to solve the question?

lucy24

9:15 pm on Jan 31, 2018 (gmt 0)

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



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 ::

iamin

8:01 pm on Feb 1, 2018 (gmt 0)

5+ Year Member



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