Rewriting rules - Moving from .htaccess to PHP

0

I am working on a web API and also on a public interface, and I need to re-write files as /create.php so that they can be accessed with just /create . This, but in PHP.

I'm sure that using PHP instead of a file .htaccess has more options, and, of course, it's easier to use, especially when I'm working on a web application written on it.

Thanks for your answers.

    
asked by Derek Nichols 02.08.2017 в 02:48
source

1 answer

0

To manipulate the URLs you need to interact with the web server in some way. If your web server is Apache, you need an htaccess file. You have no choice.

What you can do is create a single rule in your htaccess that redirects ALL the requests to a PHP file, and then do the routing (I mean, choose what to respond according to the request) from there manually. Virtually all frameworks do something like that.

The following is my preferred rule: if a request ends in a bar, it redirects it to a PHP:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)/$ index.php?r=$1

This rule would redirect misitio.com/blog/27/ to index.php? r = blog / 27 /

    
answered by 02.08.2017 в 08:31