Link to home
Start Free TrialLog in
Avatar of trg_dk
trg_dkFlag for Denmark

asked on

Apache mod_rewrite

I have a page "Index.php"

I'd like the url parameters passed to the script, but I'm not sure how many the user might pass...

url.com/dashboard - should redirect to index.php?action=dashboard

url.com/users/4000 - should redirect to index.php?action=users&data=4000

url.com/users/4000/free - should redirect to index.php?action=users&data=4000&extra=free


Could some one please help me out here ?

Regards,
Mark
Avatar of trg_dk
trg_dk
Flag of Denmark image

ASKER

Oh an I need to make a list of keywords NOT being redirected "images etc"

Thanks :)
Can you clarify what technologies you are using?

You talk about both Apache mod_rewrite and Microsoft IIS Web Server
Avatar of trg_dk

ASKER

Ohh, sorry wrong category :(

For this I am using Apache mod_rewrite

Sorry for that!
Avatar of Brad Howe
Here you go.

Make sure mod_rewrite is enabled in the httpd.conf and add the following rewrite rules.


RewriteEngine on

#url.com/dashboard - should redirect to index.php?action=dashboard
   RewriteRule ^dashboard/?$ index.php?action=dashboard [L]

#url.com/users/4000 - should redirect to index.php?action=users&data=4000
   RewriteRule ^dashboard/?$ index.php?action=$1&data=$2 [L]

#url.com/users/4000/free - should redirect to index.php?action=users&data=4000&extra=free
   RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)$ index.php?action=$1&data=$2&extra=$3 [L]

Cheers,
Hades666
Avatar of trg_dk

ASKER

Hades666, thanks for your reply. The Dashboard URL was only an exemple, it might as well be users, setup, profile or anything else.

I guess I need it to accept anything, besides a few reserved keywords (images/CSS/js...)

We can make it anything as it is regex but again we need to know what to want to capture.

Provide everything you want to capture and not and we can build a rule up.

Cheers,
Hades666
Avatar of trg_dk

ASKER

@hades666 thank you

I'd like to exclude images css admin static from the %1 of possible?

Thanks for your reply
ASKER CERTIFIED SOLUTION
Avatar of trg_dk
trg_dk
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trg_dk

ASKER

Thanks for your input, solved it using Google ;)