Mohammad Intsar
Mohammad Intsar

Reputation: 463

Change .php URL with id into .html

Given the PHP URL course.php?id=10 I want it to redirect to course.html and I want to use the id=10 on this page. How can I do this?

Upvotes: 0

Views: 468

Answers (2)

Madara's Ghost
Madara's Ghost

Reputation: 174977

You can't cleanly rewrite the url and not include the variable somewhere. You'll need to do something like so:

RewriteRule ^([0-9]+)/([^.]+)\.html $2.php?id=$1 [L]

Which will work for http://example.com/10/course.html.

Upvotes: 2

Devator
Devator

Reputation: 3904

Create a .htaccess file and add the following:

RewriteEngine On
RewriteRule ^([^.]+)\.html$ $1.php [L]

Upload this to the root of your files (most of the time it's /var/www/ or /home/user/public_html/.

Upvotes: 1

Related Questions