A
A
akdes2015-01-04 23:42:06
Apache HTTP Server
akdes, 2015-01-04 23:42:06

How to use mod_rewrite? How to get from url.com/foo.php -> url.com/foo?

Hello.
Lately, I've been constantly coming across pages that use incomplete links to files, to GET requests (url.com/foo/userid/2 instead of url.com/foo.php?userid=2), etc.
Hence a couple of questions:
1. Except for beauty, what else does it serve?
2. How to do it?
3. Pitfalls?
4. After the introduction, does the way php handles data change? Will isset($_GET[..]) pass? Or should we approach it differently?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Galkin, 2015-01-05
@akdes

1. SEO, if the link contains part of the request, the rating is higher. Remember Wikipedia and where it is in the results of issuance. actually a clear example: ".rf / nickname / photo album / spring_2014" which is even more understandable.
This model is very convenient for OOP. class/method/parameters + Classes and methods can be aliased.
2. Mod_rewrite. Without the rewrite mod - index.php/foo/bar/ will work (depending on which request handler). Actually, the rewrite is needed to remove the php index from the query string.
It will be necessary to make a handler for such requests with your own hands. as input there will be only one line $_SERVER['REQUEST_URI'] Which you need to "Explode on a slash" - explode( "/", $_SERVER['REQUEST_URI'] ); actually the output array is the "new $_GET".
3. You can forget about $_GET. using this technique is equivalent to unset($_GET) on the first line of the index file. (I wrote more about $_GET in this question - Post and Get requests, what is the difference between them and what is better and for what purposes? ).
It also depends on the position of the parameter in the string. you will use instead of string array keys the number in the array like if ( isset( $exploded_uri['2'] ) && $exploded_uri['2'] = 'something' ) { }
4. I think I already answered.

D
Dmitry, 2015-01-04
@zmeyjr

https://www.digitalocean.com/community/tutorials/h...

S
ShamblerR, 2015-02-18
@ShamblerR


We group (url.com/foo)(.php) and return
everything except $1
$1 goes into the furnace. mine is obvious.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question