Solved

Apache Mod Rewrite .htaccess

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to calculate height of a text using jquery 3 40
php subtract from date 2 26
Html split(text) 2 25
Jquery HTML() with ajax... replacing content 2 26
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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 count occurrences of each item in an array.

679 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