Author |
|
mad-proffessor
Joined: 13 Aug 2012 Posts: 5
|
Posted: Mon 13 Aug '12 12:39 Post subject: help with RewriteRule and XMLHttpRequest |
|
|
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
|
Posted: Mon 13 Aug '12 20:09 Post subject: |
|
|
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
|
Posted: Mon 13 Aug '12 21:46 Post subject: |
|
|
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
|
Posted: Tue 14 Aug '12 11:31 Post subject: |
|
|
I use a different function
Code: |
$url_array = explode('/',$_SERVER['REQUEST_URI']);
|
|
|
Back to top |
|
mad-proffessor
Joined: 13 Aug 2012 Posts: 5
|
Posted: Wed 29 Aug '12 13:35 Post subject: |
|
|
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
|
Posted: Thu 30 Aug '12 13:28 Post subject: |
|
|
if you are using the AcceptPathInfo turn of the rewrite engine. |
|
Back to top |
|
mad-proffessor
Joined: 13 Aug 2012 Posts: 5
|
Posted: Thu 30 Aug '12 14:07 Post subject: |
|
|
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
|
Posted: Thu 30 Aug '12 18:18 Post subject: |
|
|
How did you solve it? |
|
Back to top |
|
mad-proffessor
Joined: 13 Aug 2012 Posts: 5
|
Posted: Thu 30 Aug '12 21:21 Post subject: |
|
|
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 |
|