0

I want to change my URL from

http://website.com/movie.php?id=69

to

http://website.com/movie/69

My htaccess file is completely blank, and I don't know if i need to modify my PHP code. I've never dealt with htaccess and would prefer having direct assistance instead of some tutorial.

1 Answer 1

1

You can use this code in your DOCUMENT_ROOT/.htaccess file:

Options -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+movie\.php\?id=([^\s&]+) [NC]
RewriteRule ^ movie/%1? [R=302,L]

RewriteRule ^movie/(\d+)/?$ movie.php?id=$1 [L,QSA,NC]

Reference: Apache mod_rewrite Introduction

Apache mod_rewrite Technical Details

Sign up to request clarification or add additional context in comments.

3 Comments

That definitely worked but the original URL still shows in the bottom of the browser when hovering over a movie cover. Shouldn't the new URL be shown?
Rewrite rule cannot change links in your HTML files. You will need to update those hyperlinks yourself.
I understand. So in my PHP code i need to change the format to this <a href="movie/<?php echo $row['ID']; ?>">

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.