Good Afternoon:

I am looking to use Apache's mod_rewrite module to rearrange some URLs, but my knoweldge of regular expressions is SORELY lacking.

I would like to take a url such as:

http://www.somesite.com/folder/somepage.html

and translate it to:

http://www.somesite.com/index.php?dept=folder&page=somepage.html

and, just as likely:

http://www.somesite.com/folder/another_folder/somepage.html

to:

http://www.somesite.com/index.php?dept=folder&page=anotherfolder/somepage.html

Would someone please assist me with this? I would greatly appreciate it!

Member Avatar for TKSS

First, configure your servers and virtual servers with mod_rewrite by adding this to apache (I'm assuming you're using apache):

RewriteEngine on
RewriteLog /path/to/logs/server.rewrite.txt
RewriteLogLevel 1

Next, find out which scheme you would like to use for rewrite depending on your comfort zone with apache directives...

http://httpd.apache.org/docs/misc/rewriteguide.html

That should get you where you need to go.

I had gotten that far, but am specifically confused with how to write the regular expresssions to do the URL replacement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.