0

I wondering how I should code an index.php/controller to be able to display an image using an url like domain.com/imageid. Right now I'm displaying images using e.g domain.com/?image=imageid and collect it with $_GET superglobal array.

1 Answer 1

2

Just use rewrite_mod of apache.

In your root directory, create a file named .htaccess and write this in it :

RewriteEngine On
RewriteRule ^(.+)$ index.php?image=$1
Sign up to request clarification or add additional context in comments.

3 Comments

Okay thanks. Looks like some sort of regex? Does this rewrite domain.com/?id=imageid to domain.com/imageid only? Also I'm using ubuntu and apache2. I'm assuming by root directory its the apache2 directory I should create htaccess in? Going to read up more about it.
When i'm saying root directory, i'm talking about the root of your website (/var/www by default), not of your server. And yes, it does only this redirection. It is using regex, so you can write every rules you want.
I failing to apply this rule on my website. I have an url e.g domain/?i=345 where 345 is the image id. I've created the .htaccess file in the website root directory and applied the rules you said but the url string still shows domain/?i=345

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.