PHP and Apache combine to rewrite the URL to suit the search engine

xiaoxiao2021-03-06  55

The method of rewriting the URL is a lot, such as a REWRITE module in Apache, and the URL translation can be implemented by writing rules. . . .

I have rewritten the URL here is actually retrieved from the parameters required to PHP from the different forms of the URL!

For example, normal conditions http://www.sunthing.com/index.php?name=sunthing&sex=male?

Our parameter name is Name and SEX, the data is sunthing and Male

Our URL in Apache can appear in this form http://www.sunthing.com/index.php/name/sunthing/sex/male

So in this form, we have to analyze the URL, retrieve each parameter, and generate (input) when generating (input) links (input)

How do you do it?

There are several useful server variables in PHP, one is $ _server ['script_name "] It is the file name including the path (relative website) is another $ _server [' Request_uri '] This is the entire URL of course there are other server variables, here What used is these two, others don't say much!

The next step is to separate the file name and parameters, this part of the processing is in the file of the file name.

$ parameters_string = STR_REPLACE ($ _ server ['script_name'], "", $ _ server ['Request_uri']);

Separate each paragraph data

$ parameters_Array = split ('/', $ parameters_string);

At this time, the members of the array $ Parameters_Array are the first one is empty, the second is Name, the third is the fourth for SUNTHING, the fifth is Male.

These parameters can be used for me after separating!

How to use ? Of course, I will see your own application! .

For example, here is the query, select * from users where name = $ parameters_Array [3] and $ parameters_Array [4] = parameters_Array [5]

So do you understand this time? Originally http://www.sunthing.com/index.php?name =sunthing&sex=male? The URL looks now to be rewritten into http://www.sunthing.com/index.php/name/sunthing/sex/ Male This look URL can still be executed, and the URL of the static web page is similar to the search engine.

I am here just a stone, I hope to help everyone!

转载请注明原文地址:https://www.9cbs.com/read-118040.html

New Post(0)