UserDy
UserDy

Reputation: 357

How to modify URL with htaccess?

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.

Upvotes: 0

Views: 52

Answers (1)

anubhava
anubhava

Reputation: 785156

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

Upvotes: 1

Related Questions