user3050368
user3050368

Reputation: 13

Passing URL information into a PHP page

I am creating a website that will upload files per media device. I want to create a URL so that the users pass in a deviceId, and a device signature, like:

http://somesite/device/deviceId?devicesig='ABC123'

and on the server, I pass this to my PHP page. ( I wrote a simple PHP page in the /device directory, so I know I'm serving content from that directory)

I'm using XAMPP on Windows, and I've configure my .htaccess:

Options FollowSymLinks
<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ upload.php?q=$1 [PT,L]
</IfModule> 

As well as set:

<IfModule dir_module>
    DirectoryIndex upload.php
</IfModule>

I can access the URL as (missing the actual deviceId, of course)

http://localhost/device/upload.php?type=event&devicesig=e4876

But I want to access that URL as

http://localhost/device/A1234?type=event&devicesig=e4876

When I do so, I'm getting a "The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again." error.

How do I define/code such that the 'A1234' is considered as deviceId, not some part of the directory?

Thank you!

UPDATE:

As I read the comments below, it makes me wonder if my core assumption is incorrect. First, I'm assuming that to get all files for a device, and to get a specific file, I would use the following GET statements:

GET /device/ABC123
GET /device/ABC123/file1.dat

Therefore, my POST statement would match that hierarchy:

POST /device/ABC123/file1.dat

To the comments below, does that mean that I have to take my entire URL, and parse it after the host and resource ('device'), in order to get the correct device ('ABC123')?

Upvotes: 1

Views: 92

Answers (2)

jacouh
jacouh

Reputation: 8741

You can try this:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ upload.php?q=$1 [PT,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^device/(.*)$ /device/upload.php?deviceId=$1 [QSA,L]

Upvotes: 1

Lory Huz
Lory Huz

Reputation: 1508

Why you just don't have an url like: localhost/device?deviceId=A1234&type=event&devicesig=e4876

Upvotes: 0

Related Questions