Jump to content

Problem with url rewriting.

- - - - -

  • Please log in to reply
4 replies to this topic

#1
MicroBoy

MicroBoy

    Newbie

  • Members
  • PipPip
  • 22 posts
Is this possible to do via .htaccess?

When a user writes:
http://mysite.com/lajmet
The server will request:
http://mysite.com/kategorit.php?kid=1

And when the user writes:
http://mysite.com/lajmet/323
The server will request:
http://mysite.com/ka...p?kid=1&lid=323


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
You could certainly do this, although it would be adding a very generic solution to a htaccess file which would surely cause problems down the road if you extended your site, or it were not in that format. I would recommend implementing a controller to handle the request string.

I believe from the look of your format you are using Wordpress, is there not a plugin or option to do this for you? I've seen it done before.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
MicroBoy

MicroBoy

    Newbie

  • Members
  • PipPip
  • 22 posts
No it's not WordPress it is something I created by myself, at the moment I use the above code in .htaccess but when I browse h**p://mysite.com/lajmet it gives the error that the page does no exists but if I browse h**p://mysite.com/lajmet/323 everything it's ok.

RewriteRule ^lajmet/([0-9]+)$ kategorit.php?kid=1&lid=$1


#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
You may wish from the benefit of implementing a front controller class (and possibly models and views, i.e. MVC) to handle these pages.

In your situation, you could have /lamjet/123 redirect to controller.php?page=lamjet/123 and have controller.php split the request based on what is given (in this case a section and id), the controller class can have getidbynumber (i.e. 1) or getidbyname (i.e. lamjet) functions to simplify querying the database and retrieving the appropriate page.

This being said, I am not too familiar with this design, it would be the most suitable option rather than very specific htaccess directives which are bound to perform poorly.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
MicroBoy

MicroBoy

    Newbie

  • Members
  • PipPip
  • 22 posts
Thanks a lot for your help, I started to use something else because I realized this was a bit complicated. thanks again for your time.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users