Forum Moderators: phranque

Message Too Old, No Replies

How to Remove Backslashes with mod rewrite

backslashes, how to, remove

         

DarkEden Genesis

4:49 pm on Jan 5, 2012 (gmt 0)

10+ Year Member



Hello,

I rencently posted my weird issue.
Something is adding two backslashes to the path: "/var/www/html/update/\\PatchList.dat"
LOG
[Thu Jan 05 16:44:30 2012] [error] [client 190.199.133.61] File does not exist: /var/www/html/update/\\PatchList.dat


Those backslashe makes the file unreachable.
So I researched and made a rewrite rule inside a .htaccess file.
Anyway, it didn't worked.

RewriteEngine On
RewriteRule ^\\\\(.*) $1 [R]



What must I do? What is wrong?

lucy24

9:20 pm on Jan 5, 2012 (gmt 0)

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



Your Rule only catches requests that begin with a pair of backslashes. But the example shows a request that contains backslashes. That means you'll need a [^\\] in there somewhere to catch the part before the backslashes. And no matter what the rule says, it should end in [R=301,L].

DarkEden Genesis

9:42 pm on Jan 5, 2012 (gmt 0)

10+ Year Member



i have fixed this using (.*) and %2

RewriteEngine On
RewriteRule ^/(.*)/\\\\(.*) /$1/$2 [R=301]


and

RewriteEngine On
RewriteRule ^(.*)\\\\(.*) $1$2 [R=301]


i have tested it in the browser and both works correctly.

the problem is - the updater.exe sends a GET request to the server and somehow it never gets processed by the rewrite rule.

the logs still show /update/\\PatchList.dat

i have tried it on another server and it works fine.

if i try

ipaddress/update/\\PatchList.dat or
ipaddress/update/PatchList.dat

in the browser the redirect works fine and i see the dat file.

but the exe says it fails and i get an error in the error log and access log about file not exist "\\Patchlist.dat"


again this works fine on another server so that only leaves the way the exe interacts with apaceh on cent os?

lucy24

3:16 am on Jan 6, 2012 (gmt 0)

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



Is this your own server or shared? That is, do you control the config file, or does that happen somewhere upstream?

You said it comes through as a GET request. Is it a complete, free-standing request? That is, does it show up in the access logs with its own GET line and 404 response? Some types of requests-- auto-indexing, for example-- happen behind the scenes and may be handled differently.

I went back and looked at your previous post to make sure it was a simple 404 error rather than something horribly complicated involving mod_security. (For example, there might have been something in the config file that prevents .exe files from issuing their own GET requests. But this does not seem to be the problem.)

For starters, add an L flag so it says [R=301,L]. It should not make any difference, since the redirect works as intended when you ask for the file explicitly. But let's be safe. There's also the risk that the \\ is being added by some entirely different module, after mod_rewrite, so the redirect will have no effect anyway. But to pinpoint this you'd have to know which mods run after mod_rewrite, and see if any of them have the capacity to rename a file.

:: pause to beat head against wall in frustration ::

I've got a weird nagging feeling that someone in the last six months had an analogous issue with something being added to a filename in transit. But "\\" is not exactly a search-friendly phrase :( And it's not going to be something as simple as a misplaced \/ in javascript turning into a complete \\/

DarkEden Genesis

3:26 am on Jan 6, 2012 (gmt 0)

10+ Year Member



Lucy, check your inbox please.

This is my own server, not shared.

As I said previously, .htaccess seems to not proccess the GET request and at some point it gets two backslashes added.

lucy24

8:40 am on Jan 6, 2012 (gmt 0)

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



If it's your own server from top to bottom, you don't even need to be mucking about with htaccess. Everything can go in the config file. That way it's all collected in one place and you don't have to worry about conflicting directives in different places. I can't think of any directives that can only be used in htaccess.

Make a backup copy first! You should do this with htaccess too, but there's even more room for disaster in the config file.

DarkEden Genesis

5:47 pm on Jan 8, 2012 (gmt 0)

10+ Year Member



Once again I'm here to thank you Lucy.
Your info was helpful, your will to help also.

Everything is working fine now.
A friend of mine, Steven, has managed to do the right rewrite rule.

It was quite hard to figure out, but after many and many tests, a http debugger analyzer and a big effort, the right path could be trodden.

The worst thing was figure out that many browsers are doing a "rewrite" by itself, so when you are testing your rewrite rule you can't know if it's working or not*.

Here is a tip:
When doing a rewrite rule, DON'T USE:
Internet Explorer, Chrome, Opera, Safari.

ONLY USE: Moozila Firefox. (this is the good one)

Thank you again: Lucy and you all others that atleast were reading.
A beautiful 2012, a beautiful life.

lucy24

5:39 pm on Jan 9, 2012 (gmt 0)

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



So the weird punchline is: If you had made a mistake in your htaccess, using only \\ instead of properly escaping to \\\\

... then the Rewrite would have worked, and you would never have figured out what was really going on.

That's unnerving.