Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • 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
0
nsanden
Asked:
nsanden
1 Solution
 
sleep_furiouslyCommented:
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
 
nsandenAuthor Commented:
Thank you! Works great... We're using the .htaccess method.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

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