Solved

Apache Mod Rewrite .htaccess

Posted on 2011-09-20
2
251 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_
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now