How to make readable URLs?

Suppose I have a url http://example.com/user/me , where me is the username. When the user enters the URL into the address bar, I want to show the details of the user. I don't want urls like http://example.com/user.php?user=me

Any help appreciated while working on LAMP

+3
source share
3 answers

One way to do this is to use an apache module called mod_rewrite. You can then rewrite the URLs to /user/([a-z]+)to point to/user.php?user=$1

Find documentation mod_rewritefor details.

+5
source

: ( .htaccess, vhosts):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

, , index.php. URI , , . , , URL-, , . MVC, .

+4
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?u=$1
0
source

Source: https://habr.com/ru/post/1706878/


All Articles