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
Solved

Apache Mod Rewrite .htaccess

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

839 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