-5

Yes, this is another .httaccess question...

I swear to god I tried everything I could to make this work, but I can't understand clearly how to write the rules.

What i want is: to type in my browser "mydomain.com/x/10" and it should be interpreted as "mydonain.com/index.php?x=10" so i can get the x value and use it.

I wanna do this so it's easier to link stuff to people.

How do i do this? Also, if someone could provide me a link to a place where I can actually learn how to construct the regular expressions that htaccess use, that would be awesome.

1 Answers1

2

Yes, yet another .htaccess answer ;)

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

# Internally forward /x/10 to /index.php?x=10
RewriteRule ^x/(.*)/?$ index.php?x=$1 [L,QSA,NC]

This will redirect:

http://yourdomain.com/x/10

Internally to:

http://yourdomain.com/index.php?x=10

So on the user does not see that on the browser.


As for the link to learn about it, I found this a very good one specially because of the images describing what is going on.

Prix
  • 19,417
  • 15
  • 73
  • 132
  • 2
    gotta love ranking in the upvote credits for these questions that are asked over and over.. lol – NDBoost Feb 13 '14 at 21:50
  • 1
    @gorelative if you feel that way you should propose it as a question to the moderator candidates and see if you can change something, as I have tried in the past and no, SO doesn't want to change or so it seems. – Prix Feb 13 '14 at 21:53
  • if i'm testing this on localhost, in a /project folder inside my htdocs, should I change the RewriteBase / to /project? – Felipe Israel Feb 13 '14 at 22:23
  • @user3307966 yes. if project is the root folder for your test scenario. And in that case you might want to remove the `/` from index.php – Prix Feb 13 '14 at 22:37