Solved

mod_rewrite regular expression problem

Posted on 2003-12-04
2
197 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

19 Experts available now in Live!

Get 1:1 Help Now