Solved

mod_rewrite regular expression problem

Posted on 2003-12-04
2
200 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
URL rewriting - LAMP 7 46
Service "nameserver" appears to be down 4 623
Hosting application in Apache and Tomcat 1 111
Apache error.log 19 55
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…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

790 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