سؤال

I have a website that generates dynamic urls for all content.

It uses a function to show the content on index.php page and it's called by "action".

So, if the user wants to signup, there is a signup function calling it. If the user want's to browse downloads page, there is a downloads function calling it.

Something like this:

index.php?action=signup
index.php?action=downloads
index.php?action=news&type=type&id=id

In the last case are the news. The news are divided by type and ID, both numerics.

Type can be: article, update, etc.

My question is: HOW and WHAT must I do in order to transform it all on friendly URLs?

هل كانت مفيدة؟

المحلول

Presuming you are on an apache server, you will want to use a .htaccess file, and a method of using rules to rewrite URLs, not surprisingly called RewriteRule.

There's a ton of information through google if you search for .htaccess RewriteRule, but a great starting point is http://corz.org/serv/tricks/htaccess2.php.

You will essentially end up by putting a file called .htaccess in your public web files folder, with something like this:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(?:/(.*)){1,3} index.php?action=$1&type=$2&id=$3 [R,NC]

Note: I've not tested the above, and it will differ depending on how you want your pretty link to look.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top