logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: help with RewriteRule and XMLHttpRequest
Author
mad-proffessor



Joined: 13 Aug 2012
Posts: 5

PostPosted: Mon 13 Aug '12 12:39    Post subject: help with RewriteRule and XMLHttpRequest Reply with quote

Hello all. I have a javascript framework running on my site that makes asynchronous requests to a url that contains extraneous path. Apache sends back a 400 bad request error.
Here is my error_log information:
Sun Aug 12 21:52:51 2012] [error] [client ::1] Could not fetch resource information. [400, #0], referer: https://localhost/rest.php
[Sun Aug 12 21:52:51 2012] [error] [client ::1] The URL contains extraneous path components. The resource could not be identified. [400, #0], referer: https://localhost/rest.php
The framework -a grid specifically- sends that type of requests from a script called rest.php:
DELETE https://localhost/REST/george/george-myData.php/3
AND i want it to redirect to
https://localhost/REST/george/george-myData.php?id=3 which is valid

my htaccess Rewrite conditions:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_REFERER} https://localhost/rest.php
RewriteRule https://localhost/REST/(.*)/(.*)-myData.php/([0-9]+) https://localhost/REST/(.*)/(.*)-myData.php?id=$1

since george is dynamically generated i used (.*) but it doesnt work.
Anyone some help?

P.S: Tried also this one but doesnt work either.
RewriteCond %{DOCUMENT_ROOT}/REST/(.*)/(.*)-myData.php/(.*)$ !-f [OR]
RewriteCond %{DOCUMENT_ROOT}/REST/(.*)/(.*)-myData.php/(.*)$ !-d [OR]
RewriteCond %{DOCUMENT_ROOT}/REST/(.*)/(.*)/(.*)-myData.php/(.*)$ !-1
RewriteRule (.*)/REST/(.*)/(.*)-myData.php?id=$1 [L]
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Mon 13 Aug '12 20:09    Post subject: Reply with quote

For that you don't need rewrite rules. Just turn on AcceptPathInfo

Whithin your php script you can read it easy. That is the recommend way.

The other way would be using a dispatch file. (.htaccess version)

Code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^george-myData\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /george-myData.php [L]
</IfModule>
Back to top
mad-proffessor



Joined: 13 Aug 2012
Posts: 5

PostPosted: Mon 13 Aug '12 21:46    Post subject: Reply with quote

Oh it was that easy. Will try it tomorrow cause now i had some problems reading the url that was requested and extracting the path info and its getting late. Thanks. Hopefully php's parse_url() will work!
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 14 Aug '12 11:31    Post subject: Reply with quote

I use a different function

Code:

$url_array = explode('/',$_SERVER['REQUEST_URI']);
Back to top
mad-proffessor



Joined: 13 Aug 2012
Posts: 5

PostPosted: Wed 29 Aug '12 13:35    Post subject: Reply with quote

Hi again and thanks for replying but i still cant get it to work. I have set AcceptPathInfo On, the modules rewrite,negotiation,cgi,cgid are loaded (its a default lampp setup) but the request isn't accepted by the script.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Thu 30 Aug '12 13:28    Post subject: Reply with quote

if you are using the AcceptPathInfo turn of the rewrite engine.
Back to top
mad-proffessor



Joined: 13 Aug 2012
Posts: 5

PostPosted: Thu 30 Aug '12 14:07    Post subject: Reply with quote

Well i took another path but thanks for answering (Solved).
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Thu 30 Aug '12 18:18    Post subject: Reply with quote

How did you solve it?
Back to top
mad-proffessor



Joined: 13 Aug 2012
Posts: 5

PostPosted: Thu 30 Aug '12 21:21    Post subject: Reply with quote

I used the $_SERVER['QUERY_STRING'] which in my app is always populated with the data i need. I also thought that if the app goes online(its for my masters degree) i would have to rewrite the code to handle ORIG_PATH_INFO which some servers fill with data instead of PATH_INFO and since it didnt work i went the other way.
Back to top


Reply to topic   Topic: help with RewriteRule and XMLHttpRequest View previous topic :: View next topic
Post new topic   Forum Index -> Apache