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
LVL 2
trg_dkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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

You talk about both Apache mod_rewrite and Microsoft IIS Web Server
0
trg_dkAuthor Commented:
Ohh, sorry wrong category :(

For this I am using Apache mod_rewrite

Sorry for that!
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Brad HoweDevOps ManagerCommented:
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
0
trg_dkAuthor Commented:
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...)

0
Brad HoweDevOps ManagerCommented:
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
0
trg_dkAuthor Commented:
@hades666 thank you

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

Thanks for your reply
0
trg_dkAuthor Commented:
I ended up doing it like this :

RewriteEngine on
RewriteBase /
 
# Directories to ignore
RewriteRule ^(cms|css|images|img|admin|js|media|PFBC)(/.*)?$ - [L]
#RewriteRule ^(index\.php)$ - [L]
RewriteRule ^([a-z0-9]+)/([^/]*)/([^/]*)/?$     admin/index.php?action=$1&data=$2&extdata=$3  [NC]
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$     admin/index.php?action=$1&data=$2  [NC]
RewriteRule ^([a-z0-9]+)/?$     admin/index.php?action=$1  [NC]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
trg_dkAuthor Commented:
Thanks for your input, solved it using Google ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

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.