Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Jan 09, 2018 11:27 am 
Offline
Newbie

Joined: Tue Jan 09, 2018 10:59 am
Posts: 2
I have the following in my .htaccess file
Code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^example$ http://example.com/my%27problem [r=302,NE,L]
However, Apache (or something) seems to be stripping the %2 from the target, so that I end up with the following.
Code:
$ curl -I dbrks.co/example
HTTP/1.1 302 Found
Date: Tue, 09 Jan 2018 16:09:36 GMT
Server: Apache/2.4.18 (Ubuntu)
Location: http://example.com/my7problem
Connection: close
Content-Type: text/html; charset=iso-8859-1
I have many other "RewriteRule" lines, all of which work fine, for example...
Code:
RewriteRule ^thanksgiving16/trailhead$ https://www.google.com/maps/place/AMC+Highland+Center+at+Crawford+Notch/@44.2200498,-71.4142477,17z/ [r=302,NE,L]
Gets rewritten exactly as is.
Code:
$ curl -I dbrks.co/thanksgiving16/trailhead
HTTP/1.1 302 Found
Date: Tue, 09 Jan 2018 16:17:25 GMT
Server: Apache/2.4.18 (Ubuntu)
Location: https://www.google.com/maps/place/AMC+Highland+Center+at+Crawford+Notch/@44.2200498,-71.4142477,17z/
Connection: close
Content-Type: text/html; charset=iso-8859-1
Any idea whats going wrong?

Thanks,
Dan


Top
   
PostPosted: Tue Jan 09, 2018 3:38 pm 
Offline
Senior Member
User avatar

Joined: Sun Jan 24, 2016 4:30 am
Posts: 298
Since the % is reserved for backreferences, you are can't use it like that.

Instead, change the flags to [B,r=302,NE,L] so that the "B" escapes the backreference, % in this case.

More details and examples in the docs

_________________
:idea: I love my computer... all my friends live there.



Top
   
PostPosted: Tue Jan 09, 2018 3:59 pm 
Offline
Newbie

Joined: Tue Jan 09, 2018 10:59 am
Posts: 2
Interesting, thank you for the reply. It was very helpful, as back reference does seem to be the problem!

I tried your suggestion and changed the rule to add the B flag
Code:
RewriteRule ^example$ http://example.com/my%27problem [B,r=302,NE,L]
but the output was still wrong.
Code:
$ curl -I dbrks.co/example
HTTP/1.1 302 Found
Date: Tue, 09 Jan 2018 20:51:40 GMT
Server: Apache/2.4.18 (Ubuntu)
Location: http://example.com/my7problem
Connection: close
Content-Type: text/html; charset=iso-8859-1
However, when I manually escaped the the URL like so
Code:
RewriteRule ^example$ http://example.com/my\%27problem [r=302,NE,L]
then it produces the correct output.
Code:
$ curl -I dbrks.co/example
HTTP/1.1 302 Found
Date: Tue, 09 Jan 2018 20:53:50 GMT
Server: Apache/2.4.18 (Ubuntu)
Location: http://example.com/my%27problem
Connection: close
Content-Type: text/html; charset=iso-8859-1
Manually escaping the % signs is a good enough work around for me, but I wish I understood why the B flag did not have the same effect.


Top
   
PostPosted: Tue Jan 09, 2018 4:13 pm 
Offline
Senior Member
User avatar

Joined: Sun Jan 24, 2016 4:30 am
Posts: 298
I don't know why the B didn't work, in theory it should have, but most probably I'm missing something from the spec.

Another alternative is to use double quotes around the url without any escaping.

_________________
:idea: I love my computer... all my friends live there.



Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
RSS

Powered by phpBB® Forum Software © phpBB Group