How do I modify a url with . htacess?

Asked

Viewed 56 times

1

I have the url example.com/photo I would like to modify it for example.com/image

Note I have access to . htacess and apache modules.

1 answer

2

This article can help you URL Rewriting for Beginners.

Using what is shown in the article I believe the following code can be applied.

RewriteEngine On    # Turn on the rewriting engine
# Manda requisições com endereço de imagem para "foto.php" onde foto.php é o arquivo que 
# irá processar as requisições.
# NC informa ao apache que é case insensitive e L diz que caso esta regra seja usada as 
# demais não devem ser usadas.
RewriteRule    ^imagem/?$    foto.php    [NC,L]    

Still according to this other article Redirecting a Web Folder Directory to Another Directory in htaccess the code could be:

RewriteEngine On    # Turn on the rewriting engine
RewriteRule ^imagem/(.*)$ /foto/$1 [R=301,NC,L] 

The R=301 informs that the request must return code 301 to inform that there has been a redirect, the NC and the L work in the same way as the previous one. The $1 is Basic regular expression and represents the capture of the first capture group of the regular expression, in this case the (.*)$ which is basically all that is inserted after the image.

Try to change your file by adding this line and making sure that there is no rule before it is activated before and has the directive L, that would cause this to no longer be activated.

I hope this helps.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.