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 ?

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 :)
Can you clarify what technologies you are using?

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

For this I am using Apache mod_rewrite

Sorry for that!
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

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]

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...)

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.

trg_dkAuthor Commented:
@hades666 thank you

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

Thanks for your reply
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]

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 ;)
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.