Solved

Apache Mod Rewrite .htaccess

Posted on 2011-09-20
2
258 Views
Last Modified: 2012-06-27
Hi Guys,

I'm wondering if you can help me setup the following.

Im currently creating a PHP script on our server that will have Devices connect to it to download the latest configuration files.
I currently have the following htaccess file
 
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [NC,OR] 
RewriteCond %{REQUEST_FILENAME} -d [NC] 
RewriteRule .* - [L]
RewriteRule \.(css|jpe?g|gif|png|pdf|js|JPG|ico)$ - [L]
RewriteRule ^logon(.*)$   logon.php  [QSA,L] 
RewriteRule ^(.*)$   index.php?page=$1  [QSA,L]

Open in new window


What I am needing to do is generate a config file from a database, but it must follow a very strict format as we cannot change what the device is looking for, I can generate the file but need it to be read.

So for example

Device Model is:  x322
Device MAC is : 000000000000

Device Model is:  x420
Device MAC is : 000000000001

example domain   http://myserver.com/

currently we have the file structure of

index.php - file
logon.php - file
x322.php
x420.php


when the device connects to the server it request the connect of the file in the following format

 http://myserver.com/x322-000000000000.htm

What i need to be able to do is from that url  turn that into a model number and a mac
so that if the model is x322 it would call the following file
x322.php?mac=000000000000

so that if the model is x420 it would call the following file
 http://myserver.com/x420-000000000001.htm
it would call the following file
x420.php?mac=000000000001


I am happy to create rules for models as we only currently support 2 models on our systems, but what I need to be able to do is load the XML config from the file.


Hope i have been able to explain this in the best way possible.

Best Regards
Ben

0
Comment
Question by:Benji_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Amar Bardoliwala earned 500 total points
ID: 36568068
Hello Ben,

Can you please put following rule as second last rule in your file and try

RewriteRule ^x([0-9]+)-([0-9]+).htm$   x$1.php?mac=$2  [QSA,L]

Hope this will help you.

Thank You.

Amar.
0
 
LVL 2

Author Comment

by:Benji_
ID: 36814070
Im currently checking this solution :)

Regards
Ben
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question