Solved

mod_rewrite regular expression problem

Posted on 2003-12-04
2
199 Views
Last Modified: 2012-05-04
Hi guys...

I use:
RewriteRule ^([^/]+)*.html /index.php?name=$1

which basically turns a URL like http://www.mysite.com/page.html into http://www.mysite.com/index.php?name=page 

This works great except for one thing. I want to be able to turn URL's such as http://www.mysite.com/directory/page.html into http://www.mysite.com/index.php?name=directory/page

and http://www.mysite.com/directory1/directory2/page.html into http://www.mysite.com/index.php?name=directory1/directory2/page

Can anyone help me with that? THANKS
0
Comment
Question by:nsanden
2 Comments
 
LVL 10

Accepted Solution

by:
sleep_furiously earned 175 total points
ID: 9884161
The exact answer will depend a bit on whether your rewrite rule in in a per directory config (like in .htaccess file) or in server wide config like your httpd.conf file.

Right now, the reason it will not match is that [^/] is explicitly telling it "do not match any slash characters".

You can try changing [^/] to a single dot or period character.  That would probably work for the .htaccess (per-directory) config scenario, but would give you screwball results for the per-server config, because in that context, you may have to deal with parts of the URL above the current directory.

0
 
LVL 2

Author Comment

by:nsanden
ID: 9884724
Thank you! Works great... We're using the .htaccess method.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need assistance modifying php script 3 48
How to create web api to extract oracle data using php 4 71
Changing Sitemap Frequency on XML File 3 68
ports for sccm 2012 1 81
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

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