Solved

Apache Mod Rewrite .htaccess

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

803 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