Question for url rewriting.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MicroBoy
Forum Contributor
Posts: 112
Joined: Sat Mar 14, 2009 5:16 pm

Question for url rewriting.

Post by MicroBoy »

I do not know if this is the right place to do this question, but in a way PHP is used.Is possible to do this via .htaccess?

When a user writes:

Code: Select all

http://mysite.com/lajmet
The server will request:

Code: Select all

http://mysite.com/kategorit.php?kid=1
And when the user writes:

Code: Select all

http://mysite.com/lajmet/323
The server will request:

Code: Select all

http://mysite.com/kategorit.php?kid=1&lid=323
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Question for url rewriting.

Post by pickle »

Yes, you can do that.

When the user requests mysite.com/lajmet, you can use .htaccess to rewrite that. However, you will need to hardcode each rule to map to a kid. For example, you will need one rule that maps "lajmet" to "kategorit.php?kid=1", another that maps "abcd" to "kategorit.php?kid=2", etc. OR, you can just redirect it to a PHP file & let the PHP file figure it out. The .htaccess rule would then redirect "mysite.com/lajmet" to "mysite.com/kategorit.php?name=lajmet". Your PHP file would then determine what kid the term "lajmet" refers to.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply