• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

mod_rewrite regular expression problem

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
1 Solution
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.

nsandenAuthor Commented:
Thank you! Works great... We're using the .htaccess method.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now